Loading...
Searching...
No Matches
log.h
/* SPDX-License-Identifier: BSD-3-Clause
* Copyright 2016, Olivier MATZ <zer0@droids-corp.org>
*/
#pragma once
#include <stdarg.h>
#include <sys/queue.h>
#include <syslog.h>
#include <ecoli/assert.h>
enum ec_log_level {
EC_LOG_EMERG = 0,
EC_LOG_ALERT = 1,
EC_LOG_CRIT = 2,
EC_LOG_ERR = 3,
EC_LOG_WARNING = 4,
EC_LOG_NOTICE = 5,
EC_LOG_INFO = 6,
EC_LOG_DEBUG = 7,
};
struct ec_log_type {
TAILQ_ENTRY(ec_log_type) next;
const char *name;
enum ec_log_level level;
int id;
};
#define EC_LOG_TYPE_REGISTER(name) \
static struct ec_log_type name##_log_type = { \
.n##ame = #name, \
}; \
static int ec_log_local_type; \
__attribute__((constructor, used)) static void ec_log_register_##name(void) \
{ \
ec_log_local_type = ec_log_type_register(&name##_log_type); \
ec_assert_print(ec_log_local_type >= 0, "cannot register log type.\n"); \
}
typedef int (*ec_log_t)(int type, enum ec_log_level level, void *opaque, const char *str);
int ec_log_fct_register(ec_log_t usr_log, void *opaque);
int ec_log_type_register(struct ec_log_type *type);
const char *ec_log_name(int type);
int ec_log(int type, enum ec_log_level level, const char *format, ...)
__attribute__((format(__printf__, 3, 4)));
int ec_vlog(int type, enum ec_log_level level, const char *format, va_list ap);
#define EC_LOG(level, args...) ec_log(ec_log_local_type, level, args)
#define EC_VLOG(level, fmt, ap) ec_vlog(ec_log_local_type, level, fmt, ap)
int ec_log_default_cb(int type, enum ec_log_level level, void *opaque, const char *str);
int ec_log_level_set(enum ec_log_level level);
enum ec_log_level ec_log_level_get(void);
ec_log_t
int(* ec_log_t)(int type, enum ec_log_level level, void *opaque, const char *str)
User log function type.
Definition log.h:98
ec_log_level_set
int ec_log_level_set(enum ec_log_level level)
Set the global log level.
ec_log_fct_register
int ec_log_fct_register(ec_log_t usr_log, void *opaque)
Register a user log function.
ec_log_default_cb
int ec_log_default_cb(int type, enum ec_log_level level, void *opaque, const char *str)
Default log handler.
ec_log
int ec_log(int type, enum ec_log_level level, const char *format,...) __attribute__((format(__printf__
Log a formatted string.
ec_log_level
ec_log_level
Log levels, from most critical to least critical.
Definition log.h:29
ec_vlog
int int ec_vlog(int type, enum ec_log_level level, const char *format, va_list ap)
Log a formatted string.
ec_log_name
const char * ec_log_name(int type)
Return the log name associated with the log type identifier.
ec_log_type_register
int ec_log_type_register(struct ec_log_type *type)
Register a named log type.
ec_log_level_get
enum ec_log_level ec_log_level_get(void)
Get the global log level.
EC_LOG_EMERG
@ EC_LOG_EMERG
system is unusable
Definition log.h:30
EC_LOG_ALERT
@ EC_LOG_ALERT
action must be taken immediately
Definition log.h:31
EC_LOG_CRIT
@ EC_LOG_CRIT
critical conditions
Definition log.h:32
EC_LOG_INFO
@ EC_LOG_INFO
informational
Definition log.h:36
EC_LOG_WARNING
@ EC_LOG_WARNING
warning conditions
Definition log.h:34
EC_LOG_NOTICE
@ EC_LOG_NOTICE
normal but significant condition
Definition log.h:35
EC_LOG_ERR
@ EC_LOG_ERR
error conditions
Definition log.h:33
EC_LOG_DEBUG
@ EC_LOG_DEBUG
debug-level messages
Definition log.h:37
ec_log_type
A structure describing a log type.
Definition log.h:45
ec_log_type::level
enum ec_log_level level
The log level for this type.
Definition log.h:48
ec_log_type::id
int id
The log identifier.
Definition log.h:49