Nilorea Library
C utilities for networking, threading, graphics
Loading...
Searching...
No Matches
n_log.h
Go to the documentation of this file.
1
8#ifndef __LOG_HEADER_GUARD__
9#define __LOG_HEADER_GUARD__
10
11#ifdef __cplusplus
12extern "C" {
13#endif
14
20#include <stdio.h>
21#include <stdlib.h>
22#include <sys/stat.h>
23#include <pthread.h>
24#include "n_common.h"
25
27#define LOG_NULL -1
29#define LOG_FILE -3
31#define LOG_STDERR -4
33#define LOG_SYSJRNL 100
34
35#if defined(__linux__) || defined(__sun)
36
37#include <syslog.h>
38#include <pthread.h>
39
40#ifdef __sun
41#include <sys/varargs.h>
42#else
43#include <stdarg.h>
44#endif
45
46#else
47
48#include <stdarg.h>
49
51#define LOG_EMERG 0
53#define LOG_ALERT 1
55#define LOG_CRIT 2
57#define LOG_ERR 3
59#define LOG_WARNING 4
61#define LOG_NOTICE 5
63#define LOG_INFO 6
65#define LOG_DEBUG 7
66
67#endif
68
70#define n_log(__LEVEL__, ...) \
71 do { \
72 _n_log(__LEVEL__, __FILE__, __func__, __LINE__, __VA_ARGS__); \
73 } while (0)
74
76typedef struct TS_LOG {
78 pthread_mutex_t LOG_MUTEX;
80 FILE* file;
81} TS_LOG;
82
83/* Open a syslog / set name for event log */
84char* open_sysjrnl(char* identity);
85/* close syslog / free name for event log */
86void close_sysjrnl(void);
87/* Set global log level. Possible values: NOLOG , NOTICE , VERBOSE , ERROR , DEBUG */
88void set_log_level(const int log_level);
89/* Return the global log level. Possible values: NOLOG , NOTICE , VERBOSE , ERROR , DEBUG */
90int get_log_level(void);
91/* set a file as standard log output */
92int set_log_file(char* file);
93/* get the log gile name if any */
94FILE* get_log_file(void);
95/* Full log function. Muste be wrapped in a MACRO to get the correct file-func-line informations */
96void _n_log(int level, const char* file, const char* func, int line, const char* format, ...);
97
98/* Open a thread-safe logging file */
99int open_safe_logging(TS_LOG** log, char* pathname, char* opt);
100/* write to a thread-safe logging file */
101int write_safe_log(TS_LOG* log, char* pat, ...);
102/* close a thread-safe logging file */
103int close_safe_logging(TS_LOG* log);
104
109#ifdef __cplusplus
110}
111#endif
112#endif
int log_level
Definition ex_fluid.c:43
pthread_mutex_t LOG_MUTEX
mutex for thread-safe writting
Definition n_log.h:78
FILE * file
File handler.
Definition n_log.h:80
FILE * get_log_file(void)
return the current log_file
Definition n_log.c:174
int write_safe_log(TS_LOG *log, char *pat,...)
write to a thread-safe logging file
Definition n_log.c:404
int open_safe_logging(TS_LOG **log, char *pathname, char *opt)
Open a thread-safe logging file.
Definition n_log.c:338
char * open_sysjrnl(char *identity)
Open connection to syslog or create internals for event log.
Definition n_log.c:77
void close_sysjrnl(void)
Close syslog connection or clean internals 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:432
int set_log_file(char *file)
Set the logging to a file instead of stderr.
Definition n_log.c:151
void set_log_level(const int log_level)
Set the global log level value ( static int LOG_LEVEL )
Definition n_log.c:104
void _n_log(int level, const char *file, const char *func, int line, const char *format,...)
Logging function.
Definition n_log.c:244
int get_log_level(void)
Get the global log level value.
Definition n_log.c:142
ThreadSafe LOGging structure.
Definition n_log.h:76
Common headers and low-level functions & define.