|
cwist
Modern C web framework with libttak runtime
|
Application-level structured logging. More...
#include <stddef.h>#include <stdbool.h>#include <stdarg.h>

Go to the source code of this file.
Classes | |
| struct | cwist_logger |
Typedefs | |
| typedef struct cwist_logger | cwist_logger |
Enumerations | |
| enum | cwist_log_level_t { CWIST_LOG_DEBUG , CWIST_LOG_INFO , CWIST_LOG_WARN , CWIST_LOG_ERROR } |
Functions | |
Lifecycle | |
| cwist_logger * | cwist_logger_create (const char *name) |
| Create a logger. | |
| void | cwist_logger_destroy (cwist_logger *log) |
| Destroy a logger. | |
Configuration | |
| void | cwist_logger_set_level (cwist_logger *log, cwist_log_level_t level) |
| Set the minimum log level. | |
| void | cwist_logger_set_colors (cwist_logger *log, bool enabled) |
| Enable or disable colored output. | |
Logging | |
| void | cwist_logger_log (cwist_logger *log, cwist_log_level_t level, const char *fmt,...) |
| Write a log message. | |
| void | cwist_logger_debug (cwist_logger *log, const char *fmt,...) |
| Write a debug message. | |
| void | cwist_logger_info (cwist_logger *log, const char *fmt,...) |
| Write an info message. | |
| void | cwist_logger_warn (cwist_logger *log, const char *fmt,...) |
| Write a warning message. | |
| void | cwist_logger_error (cwist_logger *log, const char *fmt,...) |
| Write an error message. | |
Async output | |
Opt-in background writer for cwist_logger_* lines and the built-in access-log middleware (cwist_mw_access_log()). Callers format the line and queue it; one writer thread does the write() calls, so the request path makes no syscall. Lines stay whole and in order per stream, a full buffer makes the caller wait (nothing is dropped), and a line larger than the buffer is written synchronously. | |
| bool | cwist_log_async_start (size_t buffer_bytes) |
| Start the background log writer. | |
| void | cwist_log_async_flush (void) |
| Block until every line queued so far has been written. | |
| void | cwist_log_async_stop (void) |
| Write out queued lines, stop the writer and return to synchronous output. | |
| bool | cwist_log_async_active (void) |
| Whether the background log writer is active. | |
Application-level structured logging.
Definition in file logger.h.
Whether the background log writer is active.
Whether the background log writer is active.
Definition at line 256 of file log_async.c.
References cap.
Block until every line queued so far has been written.
Block until every line queued so far has been written.
Definition at line 221 of file log_async.c.
References cap.
Start the background log writer.
| buffer_bytes | Buffer size per stream (stdout and stderr); 0 selects 256 KiB. |
Start the background log writer.
| buffer_bytes | Ring size per stream (stdout and stderr); 0 selects 256 KiB. |
Definition at line 176 of file log_async.c.
References cap, cwist_alloc(), cwist_free(), LOG_ASYNC_DEFAULT_BYTES, and LOG_ASYNC_STREAMS.
Write out queued lines, stop the writer and return to synchronous output.
Write out queued lines, stop the writer and return to synchronous output.
Definition at line 229 of file log_async.c.
References cap, cwist_free(), and LOG_ASYNC_STREAMS.
| cwist_logger * cwist_logger_create | ( | const char * | name | ) |
Create a logger.
Create a logger.
| name | Logger name copied into the instance; NULL selects "cwist". |
Definition at line 32 of file logger.c.
References cap, cwist_alloc(), cwist_free(), CWIST_LOG_INFO, cwist_strdup(), cwist_logger::level, cwist_logger::name, and cwist_logger::use_colors.
Referenced by cwist_app_create().
| void cwist_logger_debug | ( | cwist_logger * | log, |
| const char * | fmt, | ||
| ... | |||
| ) |
Write a debug message.
Write a debug message.
| log | Logger to log through; NULL is safely ignored. |
| fmt | printf-style format string. |
Definition at line 154 of file logger.c.
References cap, and CWIST_LOG_DEBUG.
| void cwist_logger_destroy | ( | cwist_logger * | log | ) |
Destroy a logger.
Destroy a logger.
| log | Logger to free; NULL is safely ignored. |
Definition at line 48 of file logger.c.
References cwist_free(), and cwist_logger::name.
Referenced by cwist_app_destroy().
| void cwist_logger_error | ( | cwist_logger * | log, |
| const char * | fmt, | ||
| ... | |||
| ) |
Write an error message.
Write an error message.
| log | Logger to log through; NULL is safely ignored. |
| fmt | printf-style format string. |
Definition at line 187 of file logger.c.
References cap, and CWIST_LOG_ERROR.
| void cwist_logger_info | ( | cwist_logger * | log, |
| const char * | fmt, | ||
| ... | |||
| ) |
Write an info message.
Write an info message.
| log | Logger to log through; NULL is safely ignored. |
| fmt | printf-style format string. |
Definition at line 165 of file logger.c.
References cap, and CWIST_LOG_INFO.
| void cwist_logger_log | ( | cwist_logger * | log, |
| cwist_log_level_t | level, | ||
| const char * | fmt, | ||
| ... | |||
| ) |
Write a log message.
Write a log message.
| log | Logger to log through; NULL is safely ignored. |
| level | Level of the message; messages below the logger's level are suppressed. |
| fmt | printf-style format string. |
Definition at line 143 of file logger.c.
References cap.
| void cwist_logger_set_colors | ( | cwist_logger * | log, |
| bool | enabled | ||
| ) |
Enable or disable colored output.
Enable or disable colored output.
| log | Logger to configure; NULL is safely ignored. |
| enabled | true to colorize level prefixes, false for plain output. |
Definition at line 66 of file logger.c.
References cwist_logger::use_colors.
| void cwist_logger_set_level | ( | cwist_logger * | log, |
| cwist_log_level_t | level | ||
| ) |
Set the minimum log level.
Set the minimum log level.
| log | Logger to configure; NULL is safely ignored. |
| level | New minimum level; messages below it are suppressed. |
Definition at line 58 of file logger.c.
References cwist_logger::level.
| void cwist_logger_warn | ( | cwist_logger * | log, |
| const char * | fmt, | ||
| ... | |||
| ) |
Write a warning message.
Write a warning message.
| log | Logger to log through; NULL is safely ignored. |
| fmt | printf-style format string. |
Definition at line 176 of file logger.c.
References cap, and CWIST_LOG_WARN.