{"id":19269687,"url":"https://github.com/pymumu/tinylog","last_synced_at":"2025-04-12T18:49:34.269Z","repository":{"id":40462065,"uuid":"125743134","full_name":"pymumu/tinylog","owner":"pymumu","description":"A lightweight C, C++ logging library developed for Linux, It is designed with high performance, asynchronized, thread-safe and process-safe;   tinylog是一个专为UNIX设计的轻量级的C/C++日志模块，其提供了高性能，异步，线程安全，进程安全的日志功能。","archived":false,"fork":false,"pushed_at":"2024-12-17T11:52:00.000Z","size":115,"stargazers_count":224,"open_issues_count":9,"forks_count":68,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-04-03T22:07:34.165Z","etag":null,"topics":["asynchronous","c","cpp","library","lightweight","log","logging","logging-library","multithreading","tinylog"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pymumu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-03-18T16:08:14.000Z","updated_at":"2025-03-22T21:03:33.000Z","dependencies_parsed_at":"2023-01-28T23:31:32.658Z","dependency_job_id":"90515915-42c6-4c6d-88fc-b406e3f8fea2","html_url":"https://github.com/pymumu/tinylog","commit_stats":{"total_commits":98,"total_committers":3,"mean_commits":"32.666666666666664","dds":0.05102040816326525,"last_synced_commit":"28408fb5cd08eaadde1baa1075ea0a01c240ca34"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pymumu%2Ftinylog","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pymumu%2Ftinylog/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pymumu%2Ftinylog/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pymumu%2Ftinylog/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pymumu","download_url":"https://codeload.github.com/pymumu/tinylog/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248618218,"owners_count":21134199,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["asynchronous","c","cpp","library","lightweight","log","logging","logging-library","multithreading","tinylog"],"created_at":"2024-11-09T20:21:14.004Z","updated_at":"2025-04-12T18:49:34.249Z","avatar_url":"https://github.com/pymumu.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TinyLog\n\n[中文REAMDME请看这里](README_zh-CN.md)\n\nTinylog 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++.\n\nIt support log archiving, asynchronized, multithreading writing, multiprocessing writing, non-blocking mode.  \n\noutput example:\n\n```C\n[2018-04-03 21:52:13,485][INFO][        example.c:7   ] This is a log message.\n```\n\narchive example:  \n\n```C\nroot@raspberrypi:/home/pi/code/tiny-log/test # ls log/ -l\ntotal 11564\n-rw-r----- 1 root root 8754060 Apr 20 21:48 test.log\n-rw-r----- 1 root root 1543852 Apr 20 21:48 test.log-20180420-214824.gz\n-rw-r----- 1 root root 1539119 Apr 20 21:48 test.log-20180420-214830.gz\n```\n\n## Features\n\n1. Log to compressed archive file.\n2. Log level output.\n3. log format customization.\n4. asynchronized log output.\n5. Multiple log file support.\n6. printf, vprintf similar interface, easy to expand.\n7. non-blocking log mode.\n8. Multithreading concurrent write.\n9. Multiprcessing concurrent write.\n10. c++ std::cout sytle log function.\n11. Output log with color.\n\n## Usage\n\n1. Include the log header file `tlog.h` in the C code.\n2. Call `tlog_init` to initialize the log module.\n3. Call `tlog` or `tlog_[debug|info|notice|warn|error|fatal]` function output log.\n4. Call `tlog_[debug|info|notice|warn|error|fatal]\u003c\u003c` output c++ log.\n5. Call `tlog_exit` to exit the shutdown log component.\n\n## Example\n\n1. Output log\n\n    ```C\n    #include \u003cstdio.h\u003e\n    #include \"tlog.h\"\n\n    int main(int argc, char *argv[])\n    {\n        tlog_init(\"example.log\", 1024 * 1024, 8, 0, 0);\n        tlog(TLOG_INFO, \"This is a log message.\\n\");\n        tlog_exit();\n        return 0;\n    }\n    ```\n\n1. Output log with color.\n\n    ```c\n    #include \u003cstdio.h\u003e\n    #include \"tlog.h\"\n\n    int main(int argc, char *argv[])\n    {\n        tlog_init(\"example.log\", 1024 * 1024, 8, 0, TLOG_SCREEN_COLOR);\n        tlog_debug(\"This is a debug message.\");    \n        tlog_info(\"This is a log message.\");\n        tlog_notice(\"This is a notice message.\");\n        tlog_warn(\"This is a warn message.\");\n        tlog_error(\"This is a error message.\");\n        tlog_fatal(\"This is a fatal message.\");\n        tlog_exit();\n        return 0;\n    }\n    ```\n\n1. Output log for c++ cout style\n\n    ```cpp\n    #include \u003cstdio.h\u003e\n    #include \"tlog.h\"\n\n    int main(int argc, char *argv[])\n    {\n        tlog_init(\"example.log\", 1024 * 1024, 8, 0, 0);\n        tlog_info \u003c\u003c \"This is a c++ cout style log message.\\n\";\n        tlog_exit();\n        return 0;\n    }\n    ```\n\n1. Independent log stream  \n\n    c printf style  \n\n    ```C\n    #include \u003cstdio.h\u003e\n    #include \"tlog.h\"\n\n    int main(int argc, char *argv[])\n    {\n        tlog_log *log = NULL;\n        tlog_init(\"example.log\", 1024 * 1024, 8, 0, 0);\n        log = tlog_open(\"another.log\", 1024 * 1024, 8, 0, TLOG_SEGMENT);\n        tlog_printf(log, \"This is a separate log stream\\n\");\n        tlog_close(log);\n        tlog_exit();\n        return 0;\n    }\n    ```\n\n    cpp std::out like style  \n\n    ```Cpp\n    #include \u003cstdio.h\u003e\n    #include \"tlog.h\"\n\n    int main(int argc, char *argv[])\n    {\n        tlog_log *log = NULL;\n        tlog_init(\"example.log\", 1024 * 1024, 8, 0, 0);\n        log = tlog_open(\"another.log\", 1024 * 1024, 8, 0, TLOG_SEGMENT);\n        tlog_out(log) \u003c\u003c \"This is a separate log stream\\n\";\n        tlog_close(log);\n        tlog_exit();\n        return 0;\n    }\n    ```\n\n## API description\n\n1. int tlog_init(const char *logfile, int maxlogsize, int maxlogcount, int buffsize, unsigned int flag);  \n    `Function`：Initialize log module  \n    `logfile`: log file  \n    `maxlogsize`: The maximum size of a single log file.  \n    `maxlogcount`: Number of archived logs.  \n    `buffsize`: Buffer size  \n    `flag`: log output flag: List of flags are as follows  \n    * `TLOG_MULTI_WRITE`: Enable multi-process write single log mode. (Note: When using this mode, the maxlogsize parameter of all processes must be the same)  \n    * `TLOG_NOCOMPRESS`: The archive log is not compressed.  \n    * `TLOG_SEGMENT`: Log segmentation, used to register the callback function, returns a complete log for subsequent processing.  \n    * `TLOG_NONBLOCK`: Do not block when buffer is insufficient.  \n    * `TLOG_SCREEN`: Output logs to the screen.\n    * `TLOG_SUPPORT_FORK`: Support fork process.\n    * `TLOG_SCREEN_COLOR`: Output logs to the screen with color.  \n\n1. tlog(level, format, ...)  \n\n    `Function`：Print log  \n    `level`: Current log Levels  \n    `format`: Log formats  \n\n1. tlog_debug, tlog_info, tlog_notice, tlog_warn, tlog_error, tlog_fatal  \n\n    `Function`：Print log, for c++ use `\u003c\u003c` output log.  \n    `format`: Log formats.  \n\n1. tlog_exit（）  \n\n    `Function`：Log component exits  \n\n1. tlog_reg_format_func(tlog_format_func func)  \n\n    `Function`：Registers a custom Format function, and the callback function is defined as：tlog_format_func  \n\n1. tlog_reg_log_output_func(tlog_log_output_func output, void *private)  \n    `Function`: Register the custom log output function. The callback function is defined as: tlog_log_output_func. The TLOG_SEGMENT flag can be set during log initialization to return the callback to an independent full log.  \n\n1. tlog_setlevel(tlog_level level)  \n\n    `Function`：Set log level，valid level are :TLOG_DEBUG, TLOG_INFO, TLOG_NOTICE, TLOG_WARN, TLOG_ERROR, TLOG_FATAL, TLOG_OFF   \n\n1. tlog_getlevel()  \n\n    `Function`：Get log level.  \n\n1. tlog_set_logfile(const char *logfile)\n\n    `Function`：Update log file.\n    `logfile`: log file  \n\n1. tlog_setlogscreen(int enable)  \n\n    `Function`：set whether the log is output to screen.  \n\n1. tlog_open(const char *logfile, int maxlogsize, int maxlogcount, int buffsize, unsigned int flag)  \n\n    `Function`: Initializes a new log stream. When finished, it is closed with tlog_cloese.  \n    `logfile`: log file.  \n    `maxlogsize`: The maximum size of a single log file.  \n    `maxlogcount`: The number of archived logs.  \n    `buffsize`: The size of the buffer.  \n    `flag`: log output flag: List of flags are as follows  \n    * `TLOG_MULTI_WRITE`: Enable multi-process write single log mode. (Note: When using this mode, the maxlogsize parameter of all processes must be the same)  \n    * `TLOG_NOCOMPRESS`: The archive log is not compressed.  \n    * `TLOG_SEGMENT`: Log segmentation, used to register the callback function, returns a complete log for subsequent processing.  \n    * `TLOG_NONBLOCK`: Do not block when buffer is insufficient.  \n    * `TLOG_SCREEN`: Output logs to the screen.  \n    `return value`: log stream handle.  \n\n1. tlog_close(tlog_log *log)  \n\n    `Function`: Turn off the log stream  \n    `log`: The log stream handle.  \n\n1. tlog_printf(tlog_log *log, const char *format, ...)  \n\n    `Function`: Print the log to the specified log stream  \n    `log`: The log stream handle.  \n    `format`: The log format.  \n\n1. tlog_out(tlog_log *log)  \n\n    `Function`: Print the log to the specified log stream, use `\u003c\u003c` output log like std::out  \n    `log`: The log stream handle.  \n\n1. tlog_vprintf(tlog_log *log, const char *format, va_list ap)  \n\n    `Function`: Print the log to the specified log stream  \n    `log`: The log stream handle.  \n    `format`: The log format.  \n    `ap`: List of parameters.  \n\n1. tlog_logscreen(tlog_log *log, int enable)  \n\n    `Function`: Set whether the log stream is output to the screen  \n    `log`: The log stream handle.  \n    `enable`: Whether to enable.  \n\n1. tlog_localtime(struct tlog_time *tm)  \n\n    `Function`: Get local time.  \n    `tm`: Local time output.  \n\n1. tlog_reg_output_func(tlog_log *log, tlog_output_func output)  \n\n    `Function`: Register the log stream output callback function. After the specified, the built-in write local file interface will be invalid. The TLOG_SEGMENT flag can be set when the log stream is initialized to return the callback to an independent complete log.\n\n1. tlog_set_private(tlog_log *log, void *private)\n\n    `Function`: Set private parameters for retrieval in the callback function.  \n    `log`: The log stream handle.  \n    `private`: private parameter.  \n\n1. tlog_get_private(tlog_log *log)  \n\n    `Function`: Get the private parameter, which is obtained from the callback function.  \n    `log`: The log stream handle.  \n    `return value`: private parameter.  \n\n1. tlog_rename_logfile(tlog_log *log, const char *logfile)\n\n    `Function`: Rename log file.  \n    `log`: The log stream handle.  \n    `logfile`: log file.  \n\n## License\n\nMIT License\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpymumu%2Ftinylog","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpymumu%2Ftinylog","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpymumu%2Ftinylog/lists"}