libcobaro-log0  1.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
log.h
Go to the documentation of this file.
1 // -*- mode: c -*-
2 #ifndef COBARO_LOG0_LOG_H
3 #define COBARO_LOG0_LOG_H
4 
5 /****************************************************************
6 COPYRIGHT_BEGIN
7 Copyright (C) 2015, cobaro.org
8 All rights reserved.
9 COPYRIGHT_END
10 ****************************************************************/
11 
12 // All available in C99
13 #include <inttypes.h>
14 #include <stdarg.h>
15 #include <stdbool.h>
16 #include <stdio.h>
17 #include <stdint.h>
18 #include <stdlib.h>
19 #include <string.h>
20 #include <time.h>
21 
50 
57 };
58 
59 
71 };
72 
73 
75 #define COBARO_LOG_PARAM_MAX (8) // Search log.c for PARAM_MAX_FIX if changed
76 
77 
82 struct cobaro_log {
83 
87  uint32_t id;
88 
90  uint32_t code;
91 
93  struct cobaro_log *next;
94 
96  uint8_t level;
97 
98  // 3 spare bytes here.
99 
101  char pad[44];
102 
104  struct {
107  uint8_t type;
108 
109  // 7 spare bytes here.
110 
112  union {
114  char s[48];
115 
117  int64_t i;
118 
120  double f;
121 
123  uint32_t ipv4;
124  } v;
126 
127 };
128 
129 // log->code is the numeric identifier for a specific log.
130 // log->p[0].type is the type of the value.
131 // log->p[0].v.s is a reference to a string value.
132 
133 
135 typedef struct cobaro_log *cobaro_log_t;
136 
138 typedef struct cobaro_loghandle *cobaro_loghandle_t;
139 
140 
141 
143 char *cobaro_log_version(void);
144 
156 cobaro_loghandle_t cobaro_log_init(char **messages);
157 
169 void cobaro_log_messages_set(cobaro_loghandle_t lh, char **messages);
170 
176 
192 cobaro_log_t cobaro_log_claim(cobaro_loghandle_t lh);
193 
207 void cobaro_log_set_string(cobaro_log_t log, int argnum, const char *source);
208 
219 void cobaro_log_set_integer(cobaro_log_t log, int argnum, int64_t source);
220 
231 void cobaro_log_set_double(cobaro_log_t log, int argnum, double source);
232 
243 void cobaro_log_set_ipv4(cobaro_log_t log, int argnum, uint32_t source);
244 
252 void cobaro_log_publish(cobaro_loghandle_t lh, cobaro_log_t log);
253 
262 cobaro_log_t cobaro_log_next(cobaro_loghandle_t lh);
263 
271 void cobaro_log_return(cobaro_loghandle_t lh, cobaro_log_t log);
272 
287 bool cobaro_log(cobaro_loghandle_t lh, cobaro_log_t log);
288 
303 void cobaro_log_to_syslog(cobaro_loghandle_t lh, cobaro_log_t log);
304 
334 int cobaro_log_to_file(cobaro_loghandle_t lh, cobaro_log_t log, FILE *f);
335 
360 int cobaro_log_to_string(cobaro_loghandle_t lh, cobaro_log_t log,
361  char *buffer, size_t buflen);
362 
374 bool cobaro_log_loglevel_set(cobaro_loghandle_t lh, int level);
375 
386 bool cobaro_log_file_set(cobaro_loghandle_t lh, FILE *f);
387 
399 
400 
401 
402 #endif /* COBARO_LOG0_LOG_H */
Normal but significant condition.
Definition: log.h:67
bool cobaro_log(cobaro_loghandle_t lh, cobaro_log_t log)
Emit a log to the loghandle&#39;s default destination.
Value is a string.
Definition: log.h:53
Informational.
Definition: log.h:68
uint32_t id
Opaque header for use in identifying this object as a log message, when multiple structure types are ...
Definition: log.h:87
void cobaro_log_set_string(cobaro_log_t log, int argnum, const char *source)
Helper function for setting a string parameter.
void cobaro_log_messages_set(cobaro_loghandle_t lh, char **messages)
Set the message catalog in use (in case you want to change language).
Action must be taken immediately.
Definition: log.h:63
cobaro_log_levels
Log levels as they come from syslog(3).
Definition: log.h:61
void cobaro_log_set_integer(cobaro_log_t log, int argnum, int64_t source)
Helper function for setting an integer parameter.
union cobaro_log::@0::@1 v
Value.
Value is a signed integer.
Definition: log.h:54
uint32_t code
Log code. Zero is successful.
Definition: log.h:90
#define COBARO_LOG_PARAM_MAX
Number of parameters in a log message structure.
Definition: log.h:75
void cobaro_log_publish(cobaro_loghandle_t lh, cobaro_log_t log)
Publish a log_t relinqushing its memory.
uint8_t level
Log level, from cobaro_log_levels enumeration.
Definition: log.h:96
int cobaro_log_to_string(cobaro_loghandle_t lh, cobaro_log_t log, char *buffer, size_t buflen)
Log a message to a string.
double f
Floating point value.
Definition: log.h:120
cobaro_log_types
Type discriminator for parameter values in logs.
Definition: log.h:52
Debug-level messages.
Definition: log.h:69
char * cobaro_log_version(void)
Printable version number.
Value is an IP address (in 32 bit network format).
Definition: log.h:56
void cobaro_log_set_double(cobaro_log_t log, int argnum, double source)
Helper function for setting an double parameter.
bool cobaro_log_loglevel_set(cobaro_loghandle_t lh, int level)
Set the log level below which we should ignore logs.
struct cobaro_log * cobaro_log_t
Log structure pointer type.
Definition: log.h:135
System is unusable.
Definition: log.h:62
cobaro_loghandle_t cobaro_log_init(char **messages)
Initialize the logging infrastructure.
char pad[44]
Pad to make us fit into 512 bytes exactly.
Definition: log.h:101
void cobaro_log_return(cobaro_loghandle_t lh, cobaro_log_t log)
Return a log structure to the free list.
char s[48]
String value.
Definition: log.h:114
int64_t i
Integer value.
Definition: log.h:117
Error conditions.
Definition: log.h:65
int cobaro_log_to_file(cobaro_loghandle_t lh, cobaro_log_t log, FILE *f)
Log a message to file.
bool cobaro_log_file_set(cobaro_loghandle_t lh, FILE *f)
Set the default log destination to be a file handle.
void cobaro_log_to_syslog(cobaro_loghandle_t lh, cobaro_log_t log)
Log a message to syslog.
uint32_t ipv4
IPv4 address (32 bit network format)
Definition: log.h:123
uint8_t type
Value type discriminant.
Definition: log.h:107
cobaro_log_t cobaro_log_claim(cobaro_loghandle_t lh)
Acquire a log structure from the handle&#39;s free list.
Value is a double.
Definition: log.h:55
Warning conditions.
Definition: log.h:66
struct cobaro_loghandle * cobaro_loghandle_t
Opaque log handle type.
Definition: log.h:138
bool cobaro_log_syslog_set(cobaro_loghandle_t lh)
Set the default log destination to be syslog.
void cobaro_log_fini(cobaro_loghandle_t lh)
Finalize the logging infrastructure.
Iterator useful.
Definition: log.h:70
struct cobaro_log::@0 p[COBARO_LOG_PARAM_MAX]
Array of parameters relevant to this log.
struct cobaro_log * next
Queue.
Definition: log.h:93
void cobaro_log_set_ipv4(cobaro_log_t log, int argnum, uint32_t source)
Helper function for setting an IPv4 parameter.
cobaro_log_t cobaro_log_next(cobaro_loghandle_t lh)
Receive a cobaro_log_t if available.
Critical conditions.
Definition: log.h:64
Log information structure.
Definition: log.h:82