Libecoli 0.11.6
Extensible COmmand LIne library
Loading...
Searching...
No Matches
log.h
1/* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2016, Olivier MATZ <zer0@droids-corp.org>
3 */
4
17
18#pragma once
19
20#include <stdarg.h>
21#include <sys/queue.h>
22#include <syslog.h>
23
24#include <ecoli/assert.h>
25
39
46 TAILQ_ENTRY(ec_log_type) next;
47 const char *name;
49 int id;
50};
51
69#define EC_LOG_TYPE_REGISTER(name) \
70 static struct ec_log_type name##_log_type = { \
71 .n##ame = #name, \
72 }; \
73 static int ec_log_local_type; \
74 __attribute__((constructor, used)) static void ec_log_register_##name(void) \
75 { \
76 ec_log_local_type = ec_log_type_register(&name##_log_type); \
77 ec_assert_print(ec_log_local_type >= 0, "cannot register log type.\n"); \
78 }
79
98typedef int (*ec_log_t)(int type, enum ec_log_level level, void *opaque, const char *str);
99
111int ec_log_fct_register(ec_log_t usr_log, void *opaque);
112
127
137const char *ec_log_name(int type);
138
151int ec_log(int type, enum ec_log_level level, const char *format, ...)
152 __attribute__((format(__printf__, 3, 4)));
153
168int ec_vlog(int type, enum ec_log_level level, const char *format, va_list ap);
169
184#define EC_LOG(level, args...) ec_log(ec_log_local_type, level, args)
185
202#define EC_VLOG(level, fmt, ap) ec_vlog(ec_log_local_type, level, fmt, ap)
203
222int ec_log_default_cb(int type, enum ec_log_level level, void *opaque, const char *str);
223
237
249
int(* ec_log_t)(int type, enum ec_log_level level, void *opaque, const char *str)
User log function type.
Definition log.h:98
int ec_log_level_set(enum ec_log_level level)
Set the global log level.
int ec_log_fct_register(ec_log_t usr_log, void *opaque)
Register a user log function.
int ec_log_default_cb(int type, enum ec_log_level level, void *opaque, const char *str)
Default log handler.
int ec_log(int type, enum ec_log_level level, const char *format,...) __attribute__((format(__printf__
Log a formatted string.
ec_log_level
Log levels, from most critical to least critical.
Definition log.h:29
int int ec_vlog(int type, enum ec_log_level level, const char *format, va_list ap)
Log a formatted string.
const char * ec_log_name(int type)
Return the log name associated with the log type identifier.
int ec_log_type_register(struct ec_log_type *type)
Register a named log type.
enum ec_log_level ec_log_level_get(void)
Get the global log level.
@ EC_LOG_EMERG
system is unusable
Definition log.h:30
@ EC_LOG_ALERT
action must be taken immediately
Definition log.h:31
@ EC_LOG_CRIT
critical conditions
Definition log.h:32
@ EC_LOG_INFO
informational
Definition log.h:36
@ EC_LOG_WARNING
warning conditions
Definition log.h:34
@ EC_LOG_NOTICE
normal but significant condition
Definition log.h:35
@ EC_LOG_ERR
error conditions
Definition log.h:33
@ EC_LOG_DEBUG
debug-level messages
Definition log.h:37
A structure describing a log type.
Definition log.h:45
enum ec_log_level level
The log level for this type.
Definition log.h:48
int id
The log identifier.
Definition log.h:49