1 Star 0 Fork 0

海石生风 / c-logger

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

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

The MIT License (MIT) Copyright (c) 2015 Yuki Suzumoto Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

C logger,fork from https://github.com/yksz/c-logger.git 展开 收起
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/ufbycd/c-logger.git
git@gitee.com:ufbycd/c-logger.git
ufbycd
c-logger
c-logger
master

搜索帮助