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
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/
#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: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.