Nilorea Library
C utilities for networking, threading, graphics
Loading...
Searching...
No Matches
n_log.h
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
27#ifndef __LOG_HEADER_GUARD__
28#define __LOG_HEADER_GUARD__
29
30#ifdef __cplusplus
31extern "C" {
32#endif
33
39#include <stdio.h>
40#include <stdlib.h>
41#include <sys/stat.h>
42#include <pthread.h>
43#include "n_common.h"
44
46#define LOG_NULL -1
48#define LOG_FILE -3
50#define LOG_STDERR -4
52#define LOG_SYSJRNL 100
53
54#if defined(__linux__) || defined(__sun)
55
56#include <syslog.h>
57#include <pthread.h>
58
59#ifdef __sun
60#include <sys/varargs.h>
61#else
62#include <stdarg.h>
63#endif
64
65#else
66
67#include <stdarg.h>
68
70#define LOG_EMERG 0
72#define LOG_ALERT 1
74#define LOG_CRIT 2
76#define LOG_ERR 3
78#define LOG_WARNING 4
80#define LOG_NOTICE 5
82#define LOG_INFO 6
84#define LOG_DEBUG 7
85
86#endif
87
89#define n_log(__LEVEL__, ...) \
90 do { \
91 _n_log(__LEVEL__, __FILE__, __func__, __LINE__, __VA_ARGS__); \
92 } while (0)
93
95typedef struct TS_LOG {
97 pthread_mutex_t LOG_MUTEX;
99 FILE* file;
100} TS_LOG;
101
103char* open_sysjrnl(const char* identity);
105void close_sysjrnl(void);
107void set_log_level(const int log_level);
109int get_log_level(void);
111int set_log_file(char* file);
113FILE* get_log_file(void);
115void _n_log(int level, const char* file, const char* func, int line, const char* format, ...);
116
118int open_safe_logging(TS_LOG** log, char* pathname, char* opt);
120int write_safe_log(TS_LOG* log, char* pat, ...);
122int close_safe_logging(TS_LOG* log);
123
128#ifdef __cplusplus
129}
130#endif
131#endif
int log_level
Definition ex_fluid.c:60
pthread_mutex_t LOG_MUTEX
mutex for thread-safe writting
Definition n_log.h:97
FILE * file
File handler.
Definition n_log.h:99
FILE * get_log_file(void)
get the log file name if any
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
void close_sysjrnl(void)
close syslog / free name for event log
Definition n_log.c:110
char * open_sysjrnl(const char *identity)
Open a syslog / set name for event log.
Definition n_log.c:94
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 a file as standard log output
Definition n_log.c:168
void set_log_level(const int log_level)
Set global log level.
Definition n_log.c:121
void _n_log(int level, const char *file, const char *func, int line, const char *format,...)
Full log function.
Definition n_log.c:268
int get_log_level(void)
Return the global log level.
Definition n_log.c:159
ThreadSafe LOGging structure.
Definition n_log.h:95
Common headers and low-level functions & define.