Nilorea Library
C utilities for networking, threading, graphics
Loading...
Searching...
No Matches
ex_log.c

Nilorea Library log api test.

Nilorea Library log api test

Author
Castagnier Mickael
Version
1.0
Date
24/10/2018
/*
* Nilorea Library
* Copyright (C) 2005-2026 Castagnier Mickael
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "nilorea/n_log.h"
int main(void) {
puts("LOG_NULL");
n_log(LOG_EMERG, "EMERG");
n_log(LOG_ALERT, "ALERT");
n_log(LOG_CRIT, "CRIT");
n_log(LOG_ERR, "ERR");
n_log(LOG_WARNING, "WARNING");
n_log(LOG_NOTICE, "NOTICE");
n_log(LOG_INFO, "INFO");
n_log(LOG_DEBUG, "DEBUG");
puts("EMERG");
n_log(LOG_EMERG, "EMERG");
n_log(LOG_ALERT, "ALERT");
n_log(LOG_CRIT, "CRIT");
n_log(LOG_ERR, "ERR");
n_log(LOG_WARNING, "WARNING");
n_log(LOG_NOTICE, "NOTICE");
n_log(LOG_INFO, "INFO");
n_log(LOG_DEBUG, "DEBUG");
puts("ALERT");
n_log(LOG_EMERG, "EMERG");
n_log(LOG_ALERT, "ALERT");
n_log(LOG_CRIT, "CRIT");
n_log(LOG_ERR, "ERR");
n_log(LOG_WARNING, "WARNING");
n_log(LOG_NOTICE, "NOTICE");
n_log(LOG_INFO, "INFO");
n_log(LOG_DEBUG, "DEBUG");
puts("CRIT");
n_log(LOG_EMERG, "EMERG");
n_log(LOG_ALERT, "ALERT");
n_log(LOG_CRIT, "CRIT");
n_log(LOG_ERR, "ERR");
n_log(LOG_WARNING, "WARNING");
n_log(LOG_NOTICE, "NOTICE");
n_log(LOG_INFO, "INFO");
n_log(LOG_DEBUG, "DEBUG");
puts("ERR");
n_log(LOG_EMERG, "EMERG");
n_log(LOG_ALERT, "ALERT");
n_log(LOG_CRIT, "CRIT");
n_log(LOG_ERR, "ERR");
n_log(LOG_WARNING, "WARNING");
n_log(LOG_NOTICE, "NOTICE");
n_log(LOG_INFO, "INFO");
n_log(LOG_DEBUG, "DEBUG");
puts("WARNING");
n_log(LOG_EMERG, "EMERG");
n_log(LOG_ALERT, "ALERT");
n_log(LOG_CRIT, "CRIT");
n_log(LOG_ERR, "ERR");
n_log(LOG_WARNING, "WARNING");
n_log(LOG_NOTICE, "NOTICE");
n_log(LOG_INFO, "INFO");
n_log(LOG_DEBUG, "DEBUG");
puts("NOTICE");
n_log(LOG_EMERG, "EMERG");
n_log(LOG_ALERT, "ALERT");
n_log(LOG_CRIT, "CRIT");
n_log(LOG_ERR, "ERR");
n_log(LOG_WARNING, "WARNING");
n_log(LOG_NOTICE, "NOTICE");
n_log(LOG_INFO, "INFO");
n_log(LOG_DEBUG, "DEBUG");
puts("INFO");
n_log(LOG_EMERG, "EMERG");
n_log(LOG_ALERT, "ALERT");
n_log(LOG_CRIT, "CRIT");
n_log(LOG_ERR, "ERR");
n_log(LOG_WARNING, "WARNING");
n_log(LOG_NOTICE, "NOTICE");
n_log(LOG_INFO, "INFO");
n_log(LOG_DEBUG, "DEBUG");
puts("DEBUG");
n_log(LOG_EMERG, "EMERG");
n_log(LOG_ALERT, "ALERT");
n_log(LOG_CRIT, "CRIT");
n_log(LOG_ERR, "ERR");
n_log(LOG_WARNING, "WARNING");
n_log(LOG_NOTICE, "NOTICE");
n_log(LOG_INFO, "INFO");
n_log(LOG_DEBUG, "DEBUG");
set_log_file("ex_log.log");
n_log(LOG_EMERG, "EMERG");
n_log(LOG_ALERT, "ALERT");
n_log(LOG_CRIT, "CRIT");
n_log(LOG_ERR, "ERR");
n_log(LOG_WARNING, "WARNING");
n_log(LOG_NOTICE, "NOTICE");
n_log(LOG_INFO, "INFO");
n_log(LOG_DEBUG, "DEBUG");
/* test get_log_level */
int current_level = get_log_level();
printf("get_log_level: %d\n", current_level);
/* test get_log_file */
printf("get_log_file: %p\n", (void*)log_file);
/* test open_sysjrnl / close_sysjrnl */
open_sysjrnl("ex_log_test");
n_log(LOG_NOTICE, "Logged after open_sysjrnl");
n_nodup_log(LOG_INFO, "Duplicated test");
n_nodup_log(LOG_INFO, "Duplicated test");
n_nodup_log(LOG_INFO, "Duplicated test");
n_nodup_log_indexed(LOG_INFO, "NODUPINDEX1", "Duplicated test 2");
n_nodup_log_indexed(LOG_INFO, "NODUPINDEX1", "Duplicated test 2");
n_nodup_log_indexed(LOG_INFO, "NODUPINDEX2", "Duplicated test 3");
n_nodup_log_indexed(LOG_INFO, "NODUPINDEX2", "Duplicated test 3");
dump_nodup_log("log_nodup.log");
TS_LOG* SAFELOG = NULL;
open_safe_logging(&SAFELOG, "ex_log_safe.log", "w");
write_safe_log(SAFELOG, "%s(%d): %s", __FILE__, __LINE__, __func__);
write_safe_log(SAFELOG, "%s(%d): %s", __FILE__, __LINE__, __func__);
write_safe_log(SAFELOG, "%s(%d): %s", __FILE__, __LINE__, __func__);
write_safe_log(SAFELOG, "%s(%d): %s", __FILE__, __LINE__, __func__);
write_safe_log(SAFELOG, "%s(%d): %s", __FILE__, __LINE__, __func__);
exit(0);
}
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.