OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
olog.h
Go to the documentation of this file.
1 
9 #ifndef __OLOG_H_
10 #define __OLOG_H_
11 
12 #include <stdarg.h>
13 #include <stdbool.h>
14 #include <stdint.h>
15 #include <stdio.h>
16 /*
17 https://en.wikipedia.org/wiki/Syslog#Severity_level
18 
19 Value Severity Keyword Description/Examples
20 0 Emergency emerg System is unusable This level should not be used by applications.
21 1 Alert alert Should be corrected immediately Loss of the primary ISP connection.
22  Ski Haus Delta has not reported status within status_timeout (120)
23 2 Critical crit Critical conditions A failure in the system's primary application.
24  Ski Haus Delta reports temperature < low_critical (30)
25 3 Error err Error conditions An application has exceeded its file storage limit and attempts to write are failing.
26  Ski Haus Delta reports temperature < low_error (32)
27 4 Warning warn May indicate that an error will occur if action is not taken. A non-root file system has only 2GB remaining.
28  Ski Haus Delta reports temperature < low_warning (36)
29 5 Notice notice Events that are unusual, but not error conditions.
30  Ski Haus Delta reports temperature < low_notice(50)
31 6 Informational info Normal operational messages that require no action. An application has started, paused or ended successfully.
32  Ski Haus Delta reports temperature 60
33 7 Debug debug Information useful to developers for debugging the application.
34 
35 The meaning of severity levels other than Emergency and Debug are relative to the application.
36 For example, if the purpose of the system is to process transactions to update customer account
37 balance information, an error in the final step should be assigned Alert level. However, an error
38 occurring in an attempt to display the ZIP code of the customer may be assigned Error or even
39 Warning level.
40 */
41 
42 #define OLOG_DEBUG 0
43 #define OLOG_INFO 1
44 #define OLOG_NOTICE 2
45 #define OLOG_WARNING 3
46 #define OLOG_ERROR 4
47 #define OLOG_CRITICAL 5
48 #define OLOG_ALERT 6
49 #define OLOG_EMERGENCY 7
50 
51 #define OLOG_CONTINUE 0
52 #define OLOG_NOERROR 0
53 #define OLOG_EXPLODED 1
54 #define OLOG_STOP 255
55 
56 typedef struct olog olog;
57 typedef struct olog_backend olog_backend;
58 
59 typedef int (*olog_print_callback)(olog *olog, olog_backend *backend, uint8_t severity, va_list args);
62 typedef int (*olog_print_error_callback)(olog *olog, olog_backend *backend, FILE* stream);
63 
64 typedef struct olog_backend {
66  int8_t min_log_level;
67 
69  int8_t max_log_level;
70 
73 
76 
79 
82 
84  void *data;
85 } olog_backend;
86 
87 extern olog *olog_global_log;
88 extern char *olog_global_config;
90 
91 olog *olog_create(olog_backend *backends, FILE *stream);
92 void olog_destroy(olog *olog);
93 
94 bool olog_has_error(olog *olog);
95 bool olog_print_error(olog *olog, FILE *stream);
96 
97 int olog_print(olog *olog, int level, ...);
98 int olog_vprint(olog *olog, int8_t level, va_list args);
99 
100 int olog_debug(olog *olog, ...);
101 int olog_info(olog *olog, ...);
102 int olog_notice(olog *olog, ...);
103 int olog_warn(olog *olog, ...);
104 int olog_err(olog *olog, ...);
105 int olog_crit(olog *olog, ...);
106 int olog_emerg(olog *olog, ...);
107 
108 #define olog_print_verbose(olog, level, ...) \
109  do { \
110  olog_print(olog, level, __VA_ARGS__); \
111  olog_print(olog, level, "Previous message at %s:%d\n", __FILE__, __LINE__); \
112  } while (0)
113 
114 #endif /* __OLOG_H_ */
char * olog_global_config
Definition: olog_loader.c:9
int olog_print(olog *olog, int level,...)
Definition: olog.c:117
int olog_warn(olog *olog,...)
int olog_crit(olog *olog,...)
int(* olog_destroy_callback)(olog *olog, olog_backend *backend)
Definition: olog.h:60
int olog_emerg(olog *olog,...)
int olog_info(olog *olog,...)
bool olog_has_error(olog *olog)
Definition: olog.c:73
int8_t min_log_level
Minimum log level to receive.
Definition: olog.h:66
olog_print_error_callback print_error_callback
Called to print an error, if one exists.
Definition: olog.h:75
olog_has_error_callback has_error_callback
Called to check if backend is valid.
Definition: olog.h:72
olog_backend olog_backends_end
Definition: olog_loader.c:10
int olog_err(olog *olog,...)
int olog_debug(olog *olog,...)
olog * olog_create(olog_backend *backends, FILE *stream)
Definition: olog.c:15
int(* olog_print_callback)(olog *olog, olog_backend *backend, uint8_t severity, va_list args)
Definition: olog.h:59
void olog_destroy(olog *olog)
Definition: olog.c:60
bool olog_print_error(olog *olog, FILE *stream)
Definition: olog.c:86
Definition: olog.c:11
olog * olog_global_log
Definition: olog_loader.c:8
olog_destroy_callback destroy_callback
Called when olog object is destroyed.
Definition: olog.h:81
void * data
Storage for backend use.
Definition: olog.h:84
level
Definition: mapgen.py:186
int8_t max_log_level
Maximum log level to receive.
Definition: olog.h:69
int(* olog_print_error_callback)(olog *olog, olog_backend *backend, FILE *stream)
Definition: olog.h:62
int(* olog_has_error_callback)(olog *olog, olog_backend *backend)
Definition: olog.h:61
olog_print_callback print_callback
Called when given data to print.
Definition: olog.h:78
int olog_notice(olog *olog,...)
int olog_vprint(olog *olog, int8_t level, va_list args)
Definition: olog.c:100