• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..26-May-2020-

src/H26-May-2020-171101

LICENSEH A D26-May-20201 KiB2016

README.mdH A D26-May-20202 KiB7149

README.md

1# log.c
2A simple logging library implemented in C99
3
4![screenshot](https://cloud.githubusercontent.com/assets/3920290/23831970/a2415e96-0723-11e7-9886-f8f5d2de60fe.png)
5
6
7## Usage
8**[log.c](src/log.c?raw=1)** and **[log.h](src/log.h?raw=1)** should be dropped
9into an existing project and compiled along with it. The library provides 6
10function-like macros for logging:
11
12```c
13log_trace(const char *fmt, ...);
14log_debug(const char *fmt, ...);
15log_info(const char *fmt, ...);
16log_warn(const char *fmt, ...);
17log_error(const char *fmt, ...);
18log_fatal(const char *fmt, ...);
19```
20
21Each function takes a printf format string followed by additional arguments:
22
23```c
24log_trace("Hello %s", "world")
25```
26
27Resulting in a line with the given format printed to stderr:
28
29```
3020:18:26 TRACE src/main.c:11: Hello world
31```
32
33
34#### log_set_quiet(int enable)
35Quiet-mode can be enabled by passing `1` to the `log_set_quiet()` function.
36While this mode is enabled the library will not output anything to stderr, but
37will continue to write to the file if one is set.
38
39
40#### log_set_level(int level)
41The current logging level can be set by using the `log_set_level()` function.
42All logs below the given level will be ignored. By default the level is
43`LOG_TRACE`, such that nothing is ignored.
44
45
46#### log_set_fp(FILE *fp)
47A file pointer where the log should be written can be provided to the library by
48using the `log_set_fp()` function. The data written to the file output is
49of the following format:
50
51```
522047-03-11 20:18:26 TRACE src/main.c:11: Hello world
53```
54
55
56#### log_set_lock(log_LockFn fn)
57If the log will be written to from multiple threads a lock function can be set.
58The function is passed a `udata` value (set by `log_set_udata()`) and the
59integer `1` if the lock should be acquired or `0` if the lock should be
60released.
61
62
63#### LOG_USE_COLOR
64If the library is compiled with `-DLOG_USE_COLOR` ANSI color escape codes will
65be used when printing.
66
67
68## License
69This library is free software; you can redistribute it and/or modify it under
70the terms of the MIT license. See [LICENSE](LICENSE) for details.
71