HiRep 0.1
Loading...
Searching...
No Matches
logger.h
Go to the documentation of this file.
1/***************************************************************************\
2* Copyright (c) 2008, Claudio Pica *
3* All rights reserved. *
4\***************************************************************************/
5
11#ifndef LOGGER_H
12#define LOGGER_H
13
14#include "input_par.h"
15#include <stdarg.h>
16
17#ifdef __cplusplus
18extern "C" {
19#endif
20
21/* ***********************************************
22 * Simple output logging facility
23 * ***********************************************
24 * SYNOPIS:
25 *
26 * Messages outputted through the function
27 *
28 * int lprintf(char *name, int level, char*, ...);
29 *
30 * where name is an ID, level defines a log level,
31 * can be written to file streams according to a
32 * specified map. The map name => filename is
33 * defined (and can be modified) using the library
34 * functions:
35 *
36 * int logger_map(char *name, char *filename);
37 * int logger_unmap(char *name);
38 * int logger_unmap_all();
39 *
40 * All unmapped IDs are written to the logger
41 * stdout stream which can be set using:
42 *
43 * int logger_stdout(char *filename);
44 *
45 * (default = program stdout)
46 *
47 * ***********************************************/
48
49/* map the ID name to the file with name filename
50 * filename can start with ">>" in which case the file
51 * is open in append mode
52 *
53 * Returns:
54 * 0 => success
55 * 1 => invalid name
56 * 2 => invalid filename
57 * 3 => cannot open new file
58 */
59int logger_map(char *name, char *filename);
60
61/* unmap the ID name
62 * all subsequent calls to lprintf with this ID
63 * are mapped to the logger stdout
64 * If the function fails the mapping is unchanged
65 *
66 * Returns:
67 * 0 => success
68 * 1 => invalid name
69 */
70int logger_unmap(char *name);
71
72/* reset the logger:
73 * all mappings are deleted
74 * all verbosity levels are deleted
75 * default verbosity level is set to 0
76 * logger stdout is mapped to application stdout
77 */
78int logger_reset();
79
80/* set the logger stdout stream
81 * if filename=0 this function reset the stream to the
82 * program stdout
83 * NB: if filename is already open as a logger stream that stream become
84 * the logger stdout and all previously names mapped to that stream now write
85 * to stdout. If stdout is then changed all those names are written to a different
86 * stream.
87 *
88 * return codes:
89 * 0 => success
90 * 1 => failed to open new file (old logger stdout remains unchanged)
91 */
92int logger_stdout(char *filename);
93
94void logger_set_input(input_logger *logger);
95
96/* set verbosity level of the logger
97 * if name==0 then set the default level
98 */
99void logger_setlevel(char *name, int v);
100int logger_getlevel(char *name);
101/* reset verbosity level for name to stardard level */
102void logger_rmlevel(char *name);
103
104/* Global enable/disable functions */
105void logger_enable();
106void logger_disable();
107
108/* log function
109 * write to the mapped stream if message level
110 * is not bigger than the logger verbosity level
111 *
112 * arguments:
113 * name -> ID of the log stream
114 * level -> log level of the message
115 * format -> the same as printf
116 *
117 * return value:
118 * the same as printf
119 *
120 */
121int lprintf(const char *name, int level, const char *format, ...);
122
123int vlprintf(const char *name, int level, const char *format, va_list args);
124
125#ifdef __cplusplus
126}
127#endif
128#endif
Definition input_par.h:82