47 #define LOGGER_ROTATE_FIFO_NAME "/tmp/rotatefifo" 48 static int32_t rotatepipe = -1;
80 if (lGlobal->
file != NULL)
83 const char *openFlags;
94 if (lGlobal->
file == NULL)
100 static void _lcheckrotation(
void) {
101 if (rotatepipe == -1)
102 rotatepipe = open(LOGGER_ROTATE_FIFO_NAME, O_RDONLY | O_NDELAY);
103 if (rotatepipe != -1) {
106 ssize_t numb = read(rotatepipe, rotbuff, 10);
107 rotbuff[numb] =
'\0';
108 if (strcmp(rotbuff,
"ROTATE\n") == 0) {
110 if (lGlobal != NULL) {
112 if (lGlobal->
file != NULL) {
113 FILE *oldFileBkp = lGlobal->
file;
114 lGlobal->
file = NULL;
118 lGlobal->
file = oldFileBkp;
135 bool configured =
FALSE;
145 bool configured =
FALSE;
147 if (lGlobal != NULL) {
159 if (rotatepipe != -1) {
171 if (lGlobal->
file != NULL)
172 fclose(lGlobal->
file);
193 if (fprintf(lGlobal->
file,
"[%12.3f][%s][%s::%"PRIi32
"]: ", time,
lSeverityMap[s], module_tree, line) < 0)
196 if (vfprintf(lGlobal->
file, fmt, args) < 0)
199 if (fputc(
'\n', lGlobal->
file) == EOF)
202 if (fflush(lGlobal->
file) == EOF)
210 if (module_tree == NULL || fmt == NULL)
214 int32_t res =
_lvprintf(module_tree, s, line, fmt, args);
222 bool opening =
FALSE;
223 bool mutex_locked =
FALSE;
224 char *expandedFileName = NULL;
234 lGlobal =
c_malloc(
sizeof(*lGlobal));
235 if (lGlobal == NULL) {
244 if (lGlobal->
mutex == NULL) {
256 if (verbosity_env != NULL) {
257 uint32_t level = (uint32_t)strtoul(verbosity_env, NULL, 0);
264 const char *real_filename = (filename_env != NULL) ? filename_env : filename;
269 if (expandedFileName == NULL) {
275 lGlobal->
filename = expandedFileName;
286 lGlobal->
file = NULL;
351 if (sevMask != NULL) {
361 int32_t ret =
c_lvprintf(locallogger, s, line, fmt, args);
369 if (locallogger == NULL || fmt == NULL) {
int32_t c_mutex_lock(c_mutex_t *m)
void c_lsetst(uint64_t time)
int32_t c_lprintf(const c_locallogger_t *locallogger, c_logger_Severity s, int32_t line, const char *__restrict fmt,...)
int32_t c_lsetsm(uint32_t sevMask)
void * c_calloc(size_t nmemb, size_t size)
static bool _lisconfigured_locked(void)
int32_t c_mutex_init(c_mutex_t *m)
int32_t c_lchangefile(FILE *file)
int32_t c_mutex_destroy(c_mutex_t *m)
static struct global_logger * lGlobal
static int32_t _lvprintf_s(const char *module_tree, c_logger_Severity s, int32_t line, const char *__restrict fmt, va_list args)
static const char lSeverityMap[][3]
int32_t c_lgetsm(uint32_t *sevMask)
static bool _lisconfigured(void)
const char *const moduletree
uint64_t c_get_time(void)
Get time in milliseconds since 00:00:00 UTC, January 1, 1970.
#define c_attribute_format(_FMT_, _ARGS_)
Functions to handle threads, inspired to C11 threads.h.
c_logger_OpenMode_t openMode
char * c_getExpandedString(const char *filename)
void * c_malloc(size_t size)
Generic wrappers to platform-dependent functions.
static uint32_t lSeverityMask
static int32_t _lconfigure(const char *filename, c_logger_OpenMode_t om)
const char *const filename
pthread_mutex_t c_mutex_t
Mutex type.
int32_t c_lvprintf(const c_locallogger_t *locallogger, c_logger_Severity s, int32_t line, const char *__restrict fmt, va_list args)
int32_t c_lresumefile(void)
static bool _lcheckmask(uint32_t mask)
int32_t c_mutex_unlock(c_mutex_t *m)
static void _lfreeglobal(void)
static int32_t _lvprintf(const char *module_tree, c_logger_Severity s, int32_t line, const char *__restrict fmt, va_list args)
static uint64_t lStartTimeMs
static int32_t _lopenfile(void)
static const uint32_t lConfiguredMask