1 Star 0 Fork 4

wangxiang / log.c

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

log.c

A simple logging library implemented in C99

screenshot

Usage

log.c and log.h should be dropped into an existing project and compiled along with it. The library provides 6 function-like macros for logging:

log_trace(const char *fmt, ...);
log_debug(const char *fmt, ...);
log_info(const char *fmt, ...);
log_warn(const char *fmt, ...);
log_error(const char *fmt, ...);
log_fatal(const char *fmt, ...);

Each function takes a printf format string followed by additional arguments:

log_trace("Hello %s", "world")

Resulting in a line with the given format printed to stderr:

20:18:26 TRACE src/main.c:11: Hello world

log_set_quiet(bool enable)

Quiet-mode can be enabled by passing true to the log_set_quiet() function. While this mode is enabled the library will not output anything to stderr, but will continue to write to files and callbacks if any are set.

log_set_level(int level)

The current logging level can be set by using the log_set_level() function. All logs below the given level will not be written to stderr. By default the level is LOG_TRACE, such that nothing is ignored.

log_add_fp(FILE *fp, int level)

One or more file pointers where the log will be written can be provided to the library by using the log_add_fp() function. The data written to the file output is of the following format:

2047-03-11 20:18:26 TRACE src/main.c:11: Hello world

Any messages below the given level are ignored. If the library failed to add a file pointer a value less-than-zero is returned.

log_add_callback(log_LogFn fn, void *udata, int level)

One or more callback functions which are called with the log data can be provided to the library by using the log_add_callback() function. A callback function is passed a log_Event structure containing the line number, filename, fmt string, va printf va_list, level and the given udata.

log_set_lock(log_LockFn fn, void *udata)

If the log will be written to from multiple threads a lock function can be set. The function is passed the boolean true if the lock should be acquired or false if the lock should be released and the given udata value.

const char* log_level_string(int level)

Returns the name of the given log level as a string.

LOG_USE_COLOR

If the library is compiled with -DLOG_USE_COLOR ANSI color escape codes will be used when printing.

License

This library is free software; you can redistribute it and/or modify it under the terms of the MIT license. See LICENSE for details.

Copyright (c) 2020 rxi 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.

简介

暂无描述 展开 收起
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/WANG_XIANG_GITEE/log.c.git
git@gitee.com:WANG_XIANG_GITEE/log.c.git
WANG_XIANG_GITEE
log.c
log.c
master

搜索帮助