Nilorea Library
C utilities for networking, threading, graphics
Loading...
Searching...
No Matches
ex_log.c
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
27#include "nilorea/n_log.h"
28#include "nilorea/n_nodup_log.h"
29
30int main(void) {
31 puts("LOG_NULL");
33 n_log(LOG_EMERG, "EMERG");
34 n_log(LOG_ALERT, "ALERT");
35 n_log(LOG_CRIT, "CRIT");
36 n_log(LOG_ERR, "ERR");
37 n_log(LOG_WARNING, "WARNING");
38 n_log(LOG_NOTICE, "NOTICE");
39 n_log(LOG_INFO, "INFO");
40 n_log(LOG_DEBUG, "DEBUG");
41 puts("EMERG");
43 n_log(LOG_EMERG, "EMERG");
44 n_log(LOG_ALERT, "ALERT");
45 n_log(LOG_CRIT, "CRIT");
46 n_log(LOG_ERR, "ERR");
47 n_log(LOG_WARNING, "WARNING");
48 n_log(LOG_NOTICE, "NOTICE");
49 n_log(LOG_INFO, "INFO");
50 n_log(LOG_DEBUG, "DEBUG");
51 puts("ALERT");
53 n_log(LOG_EMERG, "EMERG");
54 n_log(LOG_ALERT, "ALERT");
55 n_log(LOG_CRIT, "CRIT");
56 n_log(LOG_ERR, "ERR");
57 n_log(LOG_WARNING, "WARNING");
58 n_log(LOG_NOTICE, "NOTICE");
59 n_log(LOG_INFO, "INFO");
60 n_log(LOG_DEBUG, "DEBUG");
61 puts("CRIT");
63 n_log(LOG_EMERG, "EMERG");
64 n_log(LOG_ALERT, "ALERT");
65 n_log(LOG_CRIT, "CRIT");
66 n_log(LOG_ERR, "ERR");
67 n_log(LOG_WARNING, "WARNING");
68 n_log(LOG_NOTICE, "NOTICE");
69 n_log(LOG_INFO, "INFO");
70 n_log(LOG_DEBUG, "DEBUG");
71 puts("ERR");
73 n_log(LOG_EMERG, "EMERG");
74 n_log(LOG_ALERT, "ALERT");
75 n_log(LOG_CRIT, "CRIT");
76 n_log(LOG_ERR, "ERR");
77 n_log(LOG_WARNING, "WARNING");
78 n_log(LOG_NOTICE, "NOTICE");
79 n_log(LOG_INFO, "INFO");
80 n_log(LOG_DEBUG, "DEBUG");
81 puts("WARNING");
83 n_log(LOG_EMERG, "EMERG");
84 n_log(LOG_ALERT, "ALERT");
85 n_log(LOG_CRIT, "CRIT");
86 n_log(LOG_ERR, "ERR");
87 n_log(LOG_WARNING, "WARNING");
88 n_log(LOG_NOTICE, "NOTICE");
89 n_log(LOG_INFO, "INFO");
90 n_log(LOG_DEBUG, "DEBUG");
91 puts("NOTICE");
93 n_log(LOG_EMERG, "EMERG");
94 n_log(LOG_ALERT, "ALERT");
95 n_log(LOG_CRIT, "CRIT");
96 n_log(LOG_ERR, "ERR");
97 n_log(LOG_WARNING, "WARNING");
98 n_log(LOG_NOTICE, "NOTICE");
99 n_log(LOG_INFO, "INFO");
100 n_log(LOG_DEBUG, "DEBUG");
101 puts("INFO");
103 n_log(LOG_EMERG, "EMERG");
104 n_log(LOG_ALERT, "ALERT");
105 n_log(LOG_CRIT, "CRIT");
106 n_log(LOG_ERR, "ERR");
107 n_log(LOG_WARNING, "WARNING");
108 n_log(LOG_NOTICE, "NOTICE");
109 n_log(LOG_INFO, "INFO");
110 n_log(LOG_DEBUG, "DEBUG");
111 puts("DEBUG");
113 n_log(LOG_EMERG, "EMERG");
114 n_log(LOG_ALERT, "ALERT");
115 n_log(LOG_CRIT, "CRIT");
116 n_log(LOG_ERR, "ERR");
117 n_log(LOG_WARNING, "WARNING");
118 n_log(LOG_NOTICE, "NOTICE");
119 n_log(LOG_INFO, "INFO");
120 n_log(LOG_DEBUG, "DEBUG");
121 set_log_file("ex_log.log");
122 n_log(LOG_EMERG, "EMERG");
123 n_log(LOG_ALERT, "ALERT");
124 n_log(LOG_CRIT, "CRIT");
125 n_log(LOG_ERR, "ERR");
126 n_log(LOG_WARNING, "WARNING");
127 n_log(LOG_NOTICE, "NOTICE");
128 n_log(LOG_INFO, "INFO");
129 n_log(LOG_DEBUG, "DEBUG");
130
131 /* test get_log_level */
132 int current_level = get_log_level();
133 printf("get_log_level: %d\n", current_level);
134
135 /* test get_log_file */
136 FILE* log_file = get_log_file();
137 printf("get_log_file: %p\n", (void*)log_file);
138
139 /* test open_sysjrnl / close_sysjrnl */
140 open_sysjrnl("ex_log_test");
141 n_log(LOG_NOTICE, "Logged after open_sysjrnl");
143
145
146 n_nodup_log(LOG_INFO, "Duplicated test");
147 n_nodup_log(LOG_INFO, "Duplicated test");
148 n_nodup_log(LOG_INFO, "Duplicated test");
149 n_nodup_log_indexed(LOG_INFO, "NODUPINDEX1", "Duplicated test 2");
150 n_nodup_log_indexed(LOG_INFO, "NODUPINDEX1", "Duplicated test 2");
151 n_nodup_log_indexed(LOG_INFO, "NODUPINDEX2", "Duplicated test 3");
152 n_nodup_log_indexed(LOG_INFO, "NODUPINDEX2", "Duplicated test 3");
153
154 dump_nodup_log("log_nodup.log");
155
157
158 TS_LOG* SAFELOG = NULL;
159 open_safe_logging(&SAFELOG, "ex_log_safe.log", "w");
160 write_safe_log(SAFELOG, "%s(%d): %s", __FILE__, __LINE__, __func__);
161 write_safe_log(SAFELOG, "%s(%d): %s", __FILE__, __LINE__, __func__);
162 write_safe_log(SAFELOG, "%s(%d): %s", __FILE__, __LINE__, __func__);
163 write_safe_log(SAFELOG, "%s(%d): %s", __FILE__, __LINE__, __func__);
164 write_safe_log(SAFELOG, "%s(%d): %s", __FILE__, __LINE__, __func__);
165
166 close_safe_logging(SAFELOG);
167
168 exit(0);
169}
int main(void)
#define LOG_ALERT
action must be taken immediately
Definition n_log.h:71
FILE * get_log_file(void)
return the current log_file
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
#define LOG_EMERG
system is unusable
Definition n_log.h:69
#define n_log(__LEVEL__,...)
Logging function wrapper to get line and func.
Definition n_log.h:88
void close_sysjrnl(void)
Close syslog connection or clean internals for event log.
Definition n_log.c:109
#define LOG_DEBUG
debug-level messages
Definition n_log.h:83
#define LOG_ERR
error conditions
Definition n_log.h:75
char * open_sysjrnl(const char *identity)
Open connection to syslog or create internals for event log.
Definition n_log.c:93
#define LOG_CRIT
critical conditions
Definition n_log.h:73
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 the logging to a file instead of stderr.
Definition n_log.c:167
void set_log_level(const int log_level)
Set the global log level value ( static int LOG_LEVEL )
Definition n_log.c:120
#define LOG_NOTICE
normal but significant condition
Definition n_log.h:79
#define LOG_WARNING
warning conditions
Definition n_log.h:77
#define LOG_NULL
no log output
Definition n_log.h:45
#define LOG_INFO
informational
Definition n_log.h:81
int get_log_level(void)
Get the global log level value.
Definition n_log.c:158
ThreadSafe LOGging structure.
Definition n_log.h:94
#define n_nodup_log(__LEVEL__,...)
nodup log macro helper
Definition n_nodup_log.h:52
int init_nodup_log(size_t max)
initialize the no duplicate logging system
Definition n_nodup_log.c:54
int dump_nodup_log(char *file)
Dump the duplicate error log hash table in a file The table is first written to a temporary file whic...
int close_nodup_log()
Empty nodup logtable and close the no duplicate logging session.
Definition n_nodup_log.c:87
#define n_nodup_log_indexed(__LEVEL__, __PREF__,...)
nodup log indexed macro helper
Definition n_nodup_log.h:58
static FILE * log_file
static FILE handling if logging to file is enabled
Definition n_log.c:83
Generic log system.
Generic No Dup Log system.