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