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 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
14 * implied. See the License for the specific language governing
15 * permissions and limitations under the License.
16 *
17 * SPDX-License-Identifier: Apache-2.0
18 */
19
28#include "nilorea/n_log.h"
29#include "nilorea/n_nodup_log.h"
30
31int main(void) {
32 puts("LOG_NULL");
34 n_log(LOG_EMERG, "EMERG");
35 n_log(LOG_ALERT, "ALERT");
36 n_log(LOG_CRIT, "CRIT");
37 n_log(LOG_ERR, "ERR");
38 n_log(LOG_WARNING, "WARNING");
39 n_log(LOG_NOTICE, "NOTICE");
40 n_log(LOG_INFO, "INFO");
41 n_log(LOG_DEBUG, "DEBUG");
42 puts("EMERG");
44 n_log(LOG_EMERG, "EMERG");
45 n_log(LOG_ALERT, "ALERT");
46 n_log(LOG_CRIT, "CRIT");
47 n_log(LOG_ERR, "ERR");
48 n_log(LOG_WARNING, "WARNING");
49 n_log(LOG_NOTICE, "NOTICE");
50 n_log(LOG_INFO, "INFO");
51 n_log(LOG_DEBUG, "DEBUG");
52 puts("ALERT");
54 n_log(LOG_EMERG, "EMERG");
55 n_log(LOG_ALERT, "ALERT");
56 n_log(LOG_CRIT, "CRIT");
57 n_log(LOG_ERR, "ERR");
58 n_log(LOG_WARNING, "WARNING");
59 n_log(LOG_NOTICE, "NOTICE");
60 n_log(LOG_INFO, "INFO");
61 n_log(LOG_DEBUG, "DEBUG");
62 puts("CRIT");
64 n_log(LOG_EMERG, "EMERG");
65 n_log(LOG_ALERT, "ALERT");
66 n_log(LOG_CRIT, "CRIT");
67 n_log(LOG_ERR, "ERR");
68 n_log(LOG_WARNING, "WARNING");
69 n_log(LOG_NOTICE, "NOTICE");
70 n_log(LOG_INFO, "INFO");
71 n_log(LOG_DEBUG, "DEBUG");
72 puts("ERR");
74 n_log(LOG_EMERG, "EMERG");
75 n_log(LOG_ALERT, "ALERT");
76 n_log(LOG_CRIT, "CRIT");
77 n_log(LOG_ERR, "ERR");
78 n_log(LOG_WARNING, "WARNING");
79 n_log(LOG_NOTICE, "NOTICE");
80 n_log(LOG_INFO, "INFO");
81 n_log(LOG_DEBUG, "DEBUG");
82 puts("WARNING");
84 n_log(LOG_EMERG, "EMERG");
85 n_log(LOG_ALERT, "ALERT");
86 n_log(LOG_CRIT, "CRIT");
87 n_log(LOG_ERR, "ERR");
88 n_log(LOG_WARNING, "WARNING");
89 n_log(LOG_NOTICE, "NOTICE");
90 n_log(LOG_INFO, "INFO");
91 n_log(LOG_DEBUG, "DEBUG");
92 puts("NOTICE");
94 n_log(LOG_EMERG, "EMERG");
95 n_log(LOG_ALERT, "ALERT");
96 n_log(LOG_CRIT, "CRIT");
97 n_log(LOG_ERR, "ERR");
98 n_log(LOG_WARNING, "WARNING");
99 n_log(LOG_NOTICE, "NOTICE");
100 n_log(LOG_INFO, "INFO");
101 n_log(LOG_DEBUG, "DEBUG");
102 puts("INFO");
104 n_log(LOG_EMERG, "EMERG");
105 n_log(LOG_ALERT, "ALERT");
106 n_log(LOG_CRIT, "CRIT");
107 n_log(LOG_ERR, "ERR");
108 n_log(LOG_WARNING, "WARNING");
109 n_log(LOG_NOTICE, "NOTICE");
110 n_log(LOG_INFO, "INFO");
111 n_log(LOG_DEBUG, "DEBUG");
112 puts("DEBUG");
114 n_log(LOG_EMERG, "EMERG");
115 n_log(LOG_ALERT, "ALERT");
116 n_log(LOG_CRIT, "CRIT");
117 n_log(LOG_ERR, "ERR");
118 n_log(LOG_WARNING, "WARNING");
119 n_log(LOG_NOTICE, "NOTICE");
120 n_log(LOG_INFO, "INFO");
121 n_log(LOG_DEBUG, "DEBUG");
122 set_log_file("ex_log.log");
123 n_log(LOG_EMERG, "EMERG");
124 n_log(LOG_ALERT, "ALERT");
125 n_log(LOG_CRIT, "CRIT");
126 n_log(LOG_ERR, "ERR");
127 n_log(LOG_WARNING, "WARNING");
128 n_log(LOG_NOTICE, "NOTICE");
129 n_log(LOG_INFO, "INFO");
130 n_log(LOG_DEBUG, "DEBUG");
131
132 /* test get_log_level */
133 int current_level = get_log_level();
134 printf("get_log_level: %d\n", current_level);
135
136 /* test get_log_file */
137 FILE* log_file = get_log_file();
138 printf("get_log_file: %p\n", (void*)log_file);
139
140 /* test open_sysjrnl / close_sysjrnl */
141 open_sysjrnl("ex_log_test");
142 n_log(LOG_NOTICE, "Logged after open_sysjrnl");
144
146
147 n_nodup_log(LOG_INFO, "Duplicated test");
148 n_nodup_log(LOG_INFO, "Duplicated test");
149 n_nodup_log(LOG_INFO, "Duplicated test");
150 n_nodup_log_indexed(LOG_INFO, "NODUPINDEX1", "Duplicated test 2");
151 n_nodup_log_indexed(LOG_INFO, "NODUPINDEX1", "Duplicated test 2");
152 n_nodup_log_indexed(LOG_INFO, "NODUPINDEX2", "Duplicated test 3");
153 n_nodup_log_indexed(LOG_INFO, "NODUPINDEX2", "Duplicated test 3");
154
155 dump_nodup_log("log_nodup.log");
156
158
159 TS_LOG* SAFELOG = NULL;
160 open_safe_logging(&SAFELOG, "ex_log_safe.log", "w");
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 write_safe_log(SAFELOG, "%s(%d): %s", __FILE__, __LINE__, __func__);
166
167 close_safe_logging(SAFELOG);
168
169 exit(0);
170}
int main(void)
#define LOG_ALERT
action must be taken immediately
Definition n_log.h:72
FILE * get_log_file(void)
return the current log_file
Definition n_log.c:198
int write_safe_log(TS_LOG *log, char *pat,...)
write to a thread-safe logging file
Definition n_log.c:452
int open_safe_logging(TS_LOG **log, char *pathname, char *opt)
Open a thread-safe logging file.
Definition n_log.c:383
#define LOG_EMERG
system is unusable
Definition n_log.h:70
#define n_log(__LEVEL__,...)
Logging function wrapper to get line and func.
Definition n_log.h:89
void close_sysjrnl(void)
Close syslog connection or clean internals for event log.
Definition n_log.c:110
#define LOG_DEBUG
debug-level messages
Definition n_log.h:84
#define LOG_ERR
error conditions
Definition n_log.h:76
char * open_sysjrnl(const char *identity)
Open connection to syslog or create internals for event log.
Definition n_log.c:94
#define LOG_CRIT
critical conditions
Definition n_log.h:74
int close_safe_logging(TS_LOG *log)
close a thread-safe logging file
Definition n_log.c:480
int set_log_file(char *file)
Set the logging to a file instead of stderr.
Definition n_log.c:168
void set_log_level(const int log_level)
Set the global log level value ( static int LOG_LEVEL )
Definition n_log.c:121
#define LOG_NOTICE
normal but significant condition
Definition n_log.h:80
#define LOG_WARNING
warning conditions
Definition n_log.h:78
#define LOG_NULL
no log output
Definition n_log.h:46
#define LOG_INFO
informational
Definition n_log.h:82
int get_log_level(void)
Get the global log level value.
Definition n_log.c:159
ThreadSafe LOGging structure.
Definition n_log.h:95
#define n_nodup_log(__LEVEL__,...)
nodup log macro helper
Definition n_nodup_log.h:53
int init_nodup_log(size_t max)
initialize the no duplicate logging system
Definition n_nodup_log.c:55
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:88
#define n_nodup_log_indexed(__LEVEL__, __PREF__,...)
nodup log indexed macro helper
Definition n_nodup_log.h:59
static FILE * log_file
static FILE handling if logging to file is enabled
Definition n_log.c:84
Generic log system.
Generic No Dup Log system.