Giter Site home page Giter Site logo

moriartyz / tinylog Goto Github PK

View Code? Open in Web Editor NEW

This project forked from pymumu/tinylog

0.0 2.0 0.0 96 KB

A lightweight C-language log component for UNIX environment, It is a high performance, asynchronized, thread-safe and process-safe log library for C/C++; tinylog是一个专为UNIX设计的轻量级的C/C++日志模块,其提供了高性能,异步,线程安全,进程安全的日志功能。

License: MIT License

CMake 1.18% Makefile 2.61% C 96.21%

tinylog's Introduction

TinyLog

中文REAMDME请看这里

Tinylog is a lightweight C-language high performance log component for UNIX environment, It is high performance, asynchronized, thread-safe and process-safe log library for C/C++.

It support log archiving, asynchronized, multithreading writing, multiprocessing writing, non-blocking mode.

output example:

[2018-04-03 21:52:13,485][INFO][        example.c:7   ] This is a log message.

archive example:

root@raspberrypi:/home/pi/code/tiny-log/test # ls log/ -l
total 11564
-rw-r----- 1 root root 8754060 Apr 20 21:48 test.log
-rw-r----- 1 root root 1543852 Apr 20 21:48 test.log-20180420-214824.gz
-rw-r----- 1 root root 1539119 Apr 20 21:48 test.log-20180420-214830.gz

Features

  1. Log to compressed archive file.
  2. Log level output.
  3. log format customization.
  4. asynchronized log output.
  5. non-blocking log mode.
  6. Multithreading concurrent write.
  7. Multiprcessing concurrent write.

Usage

  1. Include the log header file tlog.h in the C code.
  2. Call tlog_init to initialize the log module.
  3. Call tlog function output log.
  4. Call tlog_exit to exit the shutdown log component.

Example

#include <stdio.h>
#include "tlog.h"

int main(int argc, char *argv[]) 
{
    tlog_init("./", "example.log", 1024 * 1024, 8, 1, 0, 0);
    tlog(TLOG_INFO, "This is a log message.\n");
    tlog_exit();
    return 0;
}

If you want filename wihout path in log, you can specify the macro BASE_FILE_NAME as the filename and generate as short file name when compiling. example as follows: (please check makefile in example directory.)
For makefile:

CFLAGS += -DBASE_FILE_NAME=\"$(notdir $<)\"

For cmake:

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DBASE_FILE_NAME='\"$(notdir $<)\"'")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DBASE_FILE_NAME='\"$(notdir $<)\"'")

API description

  1. int tlog_init(const char *logdir, const char *logname, int maxlogsize, int maxlogcount, int block, int buffsize);
    Function:Initialize log module
    logdir: Log Output path.
    logname: Log name.
    maxlogsize: The maximum size of a single log file.
    maxlogcount: Number of archived logs.
    block: Blocked if buffer is not sufficient.
    buffsize: Buffer size
    multiwrite: enable multi process write mode. (NOTICE: maxlogsize in all prcesses must be same when enable this mode. )

  2. tlog(level, format, ...)
    Function:Print log
    level: Current log Levels
    format: Log formats

  3. tlog_exit()
    Function:Log component exits

  4. tlog_reg_format_func(tlog_format_func func)
    Function:Registers a custom Format function, and the callback function is defined as:tlog_format_func

  5. tlog_setlevel(tlog_level level)
    Function:Set log level,valid level are :TLOG_DEBUG, TLOG_INFO, TLOG_NOTICE, TLOG_WARN, TLOG_ERROR, TLOG_FATAL.

  6. tlog_setlogscreen(int enable)
    Function:set whether the log is output to screen.

License

MIT License

tinylog's People

Contributors

pymumu avatar

Watchers

 avatar  avatar

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.