Nilorea Library
C utilities for networking, threading, graphics
Loading...
Searching...
No Matches
n_log.h
Go to the documentation of this file.
1/*
2 * Nilorea Library
3 * Copyright (C) 2005-2026 Castagnier Mickael
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18
26#ifndef __LOG_HEADER_GUARD__
27#define __LOG_HEADER_GUARD__
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
38#include <stdio.h>
39#include <stdlib.h>
40#include <sys/stat.h>
41#include <pthread.h>
42#include "n_common.h"
43
45#define LOG_NULL -1
47#define LOG_FILE -3
49#define LOG_STDERR -4
51#define LOG_SYSJRNL 100
52
53#if defined(__linux__) || defined(__sun)
54
55#include <syslog.h>
56#include <pthread.h>
57
58#ifdef __sun
59#include <sys/varargs.h>
60#else
61#include <stdarg.h>
62#endif
63
64#else
65
66#include <stdarg.h>
67
69#define LOG_EMERG 0
71#define LOG_ALERT 1
73#define LOG_CRIT 2
75#define LOG_ERR 3
77#define LOG_WARNING 4
79#define LOG_NOTICE 5
81#define LOG_INFO 6
83#define LOG_DEBUG 7
84
85#endif
86
88#define n_log(__LEVEL__, ...) \
89 do { \
90 _n_log(__LEVEL__, __FILE__, __func__, __LINE__, __VA_ARGS__); \
91 } while (0)
92
94typedef struct TS_LOG {
96 pthread_mutex_t LOG_MUTEX;
98 FILE* file;
99} TS_LOG;
100
102char* open_sysjrnl(const char* identity);
104void close_sysjrnl(void);
106void set_log_level(const int log_level);
108int get_log_level(void);
110int set_log_file(char* file);
112FILE* get_log_file(void);
114void _n_log(int level, const char* file, const char* func, int line, const char* format, ...);
115
117int open_safe_logging(TS_LOG** log, char* pathname, char* opt);
119int write_safe_log(TS_LOG* log, char* pat, ...);
121int close_safe_logging(TS_LOG* log);
122
127#ifdef __cplusplus
128}
129#endif
130#endif
int log_level
Definition ex_fluid.c:61
pthread_mutex_t LOG_MUTEX
mutex for thread-safe writting
Definition n_log.h:96
FILE * file
File handler.
Definition n_log.h:98
FILE * get_log_file(void)
get the log file name if any
Definition n_log.c:197
int write_safe_log(TS_LOG *log, char *pat,...)
write to a thread-safe logging file
Definition n_log.c:451
int open_safe_logging(TS_LOG **log, char *pathname, char *opt)
Open a thread-safe logging file.
Definition n_log.c:382
void close_sysjrnl(void)
close syslog / free name for event log
Definition n_log.c:109
char * open_sysjrnl(const char *identity)
Open a syslog / set name for event log.
Definition n_log.c:93
int close_safe_logging(TS_LOG *log)
close a thread-safe logging file
Definition n_log.c:479
int set_log_file(char *file)
set a file as standard log output
Definition n_log.c:167
void set_log_level(const int log_level)
Set global log level.
Definition n_log.c:120
void _n_log(int level, const char *file, const char *func, int line, const char *format,...)
Full log function.
Definition n_log.c:267
int get_log_level(void)
Return the global log level.
Definition n_log.c:158
ThreadSafe LOGging structure.
Definition n_log.h:94
Common headers and low-level functions & define.