File size: 1,766 Bytes
8b7c501 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# clog: C-style (a-la printf) logging library
[![BSD (2 clause) License](https://img.shields.io/badge/License-BSD%202--Clause%20%22Simplified%22%20License-blue.svg)](https://github.com/pytorch/cpuinfo/blob/master/deps/clog/LICENSE)
C-style library for logging errors, warnings, information notes, and debug information.
## Features
- printf-style interface for formatting variadic parameters.
- Separate functions for logging errors, warnings, information notes, and debug information.
- Independent logging settings for different modules.
- Logging to logcat on Android and stderr/stdout on other platforms.
- Compatible with C99 and C++.
- Covered with unit tests.
## Example
```c
#include <clog.h>
#ifndef MYMODULE_LOG_LEVEL
#define MYMODULE_LOG_LEVEL CLOG_DEBUG
#endif
CLOG_DEFINE_LOG_DEBUG(mymodule_, "My Module", MYMODULE_LOG_LEVEL);
CLOG_DEFINE_LOG_INFO(mymodule_, "My Module", MYMODULE_LOG_LEVEL);
CLOG_DEFINE_LOG_WARNING(mymodule_, "My Module", MYMODULE_LOG_LEVEL);
CLOG_DEFINE_LOG_ERROR(mymodule_, "My Module", MYMODULE_LOG_LEVEL);
...
void some_function(...) {
int status = ...
if (status != 0) {
mymodule_log_error(
"something really bad happened: "
"operation failed with status %d", status);
}
uint32_t expected_zero = ...
if (expected_zero != 0) {
mymodule_log_warning(
"something suspicious happened (var = %"PRIu32"), "
"fall back to generic implementation", expected_zero);
}
void* usually_non_null = ...
if (usually_non_null == NULL) {
mymodule_log_info(
"something unusual, but common, happened: "
"enabling work-around");
}
float a = ...
mymodule_log_debug("computed a = %.7f", a);
}
```
|