Giter Club home page Giter Club logo

c-logger's Introduction

Build Status

C logger

Table of Contents

What is this?

This is a simple logging library for C/C++.

This library's main features:

  • Lightweight - only 500-line source code
  • C89 support
  • Thread-safe
  • 2 logging types:
    • Console logging
    • File logging rotated by file size
  • Custom with a configuration file

Installation

./build.sh
cd build
make
sudo make install

or

build.bat

or

Copy files in src directory to your project

Platform

  • Windows (Visual Studio 2008+)
  • Mac OS X (clang 3.6+)
  • Linux (gcc 4.8.4+)

Note: Operations are confirmed on the above platforms

Benchmark

This following table comparing other libraries is benchmark results to log 1,000,000 times.

threads c-logger glog
1 0.832s 1.267s
10 1.386s 1.183s

Benchmark environment

  • Processor: Intel Core i3-4170 CPU @ 3.70GHz
  • Memory: 8.0GB
  • OS: Ubuntu 16.04 64bit

Log format

level yy-MM-dd hh:mm:ss:uuuuuu threadid file:line: message

Example

Console logging

logger_initConsoleLogger(stderr);
logger_setLevel(LogLevel_DEBUG);
LOG_INFO("console logging");

File logging

logger_initFileLogger("logs/log.txt", 1024 * 1024, 5);
logger_setLevel(LogLevel_DEBUG);
LOG_INFO("file logging");
LOG_DEBUG("format example: %d%c%s", 1, '2', "3");

The output of the file logger is the following:

I 15-11-10 00:32:43.771455 2854 filelogger.c:6: file logging
D 15-11-10 00:32:43.771564 2854 filelogger.c:7: format example: 123

Multi logging

logger_initConsoleLogger(NULL);
logger_initFileLogger("logs/log.txt", 0, 0);
LOG_INFO("multi logging");

License

The MIT license

c-logger's People

Contributors

bwrsandman avatar rem0obb avatar yksz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

c-logger's Issues

Enhancement: logger_deinit to avoid valgrind report memory leak

Hi there,

There will always have memory leak detected by valgrind when using file logger, and it will disable if not using file logger.

Is there possible create a logger_deinit function to let caller to release the stuffs inside c-logger?

Thanks

==151761== 
==151761== HEAP SUMMARY:
==151761==     in use at exit: 472 bytes in 1 blocks
==151761==   total heap usage: 797 allocs, 796 frees, 1,555,765 bytes allocated
==151761== 
==151761== 472 bytes in 1 blocks are still reachable in loss record 1 of 1
==151761==    at 0x4848899: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==151761==    by 0x4BDE6CD: __fopen_internal (iofopen.c:65)
==151761==    by 0x4BDE6CD: fopen@@GLIBC_2.2.5 (iofopen.c:86)
==151761==    by 0x48FE7D5: logger_initFileLogger (logger.c:174)
==151761==    by 0x10CB6E: main (main.cpp:47)
==151761== 
==151761== LEAK SUMMARY:
==151761==    definitely lost: 0 bytes in 0 blocks
==151761==    indirectly lost: 0 bytes in 0 blocks
==151761==      possibly lost: 0 bytes in 0 blocks
==151761==    still reachable: 472 bytes in 1 blocks
==151761==         suppressed: 0 bytes in 0 blocks
==151761== 
==151761== For lists of detected and suppressed errors, rerun with: -s
==151761== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.