1MS_LOG(3)                  Library Functions Manual                  MS_LOG(3)
2
3
4

NAME

6       ms_log - Central logging facility for libmseed
7
8

SYNOPSIS

10       #include <libmseed.h>
11
12       int  ms_log (int level, const char *format, ...);
13
14       int  ms_log_l (MSLogParam *logp, int level, const char *format, ...);
15
16       void ms_loginit (void (*log_print)(char*), const char *logprefix,
17                        void (*diag_print)(char*), const char *errprefix);
18
19       MSLogParam * ms_loginit_l (MSLogParam *logp,
20                      void (*log_print)(char*), const char *logprefix,
21                      void (*diag_print)(char*), const char *errprefix);
22

DESCRIPTION

24       The  ms_log  functions  are the central logging facility for all output
25       from libmseed functions.  They are also intended to be used by libmseed
26       based programs if desired.
27
28       Three message levels are recognized:
29        0  : Normal log messgaes, printed using log_print with logprefix
30        1  : Diagnostic messages, printed using diag_print with logprefix
31        2+ : Error messages, printed using diag_print with errprefix
32
33       It is the task of the ms_log functions to format a message using printf
34       conventions and pass the formatted string to the  appropriate  printing
35       function (log_print or diag_print)
36
37       ms_log will process messages using the global logging parameters.
38
39       ms_log_l  is  a  reentrant  version of ms_log.  It will use the logging
40       parameters specified in the supplied MSLogParam  struct.   If  logp  is
41       NULL global parameters will be used, this would be equivalent to a call
42       to ms_log().  This is intended for use only  when  complicated  logging
43       schemes  are  desired, e.g. in a threaded application.  Note that it is
44       not possible to set thread specific logging parameters for the internal
45       library functions because global parameters are used.
46
47       The  ms_loginit  functions  are  used to set the log and error printing
48       functions and the log and error message prefixes  used  by  the  ms_log
49       functions.
50
51       ms_loginit will operate on the global logging parameters.
52
53       ms_loginit_l  is a reentrant version of ms_loginit.  It will initialize
54       or change the logging parameters specified in  the  MSLogParam  struct.
55       If  logp  is NULL a new MSLogParam struct will be allocated.  A pointer
56       to the created or re-initialized MSLogParam struct  will  be  returned.
57       The returned pointer is suitable for use with ms_log_l.
58
59       Use NULL for the print function pointers or the prefixes if they should
60       not be changed from previously set or default values.
61
62       The default values for the logging parameters are:
63         log_print  = fprintf  (printing to standard out)
64         log_prefix = ""
65         diag_print = fprintf  (printing to standard error)
66         err_prefix = "error: "
67
68       By setting the printing functions it is possible to  re-direct  all  of
69       the  output from these logging routines.  This is useful when the libm‐
70       seed based software is embedded in  a  system  with  it's  own  logging
71       facilities.
72
73       Most  of  the libmseed internal messages are logged at either the diag‐
74       nostic or error level.
75
76

RETURN VALUES

78       ms_log and ms_log_l return the number of characters formatted  on  suc‐
79       cess, and a negative value on error.
80
81       ms_loginit_l  returns  a pointer to the MSLogParam struct that it oper‐
82       ated on.  If the input MSLogParam struct is NULL a new struct  will  be
83       allocated with malloc().
84
85

EXAMPLE

87       Unless a complicated logging scheme is needed most uses of this logging
88       facility will be limited to the ms_loginit and ms_log functions.
89
90       An example of setting the printing functions:
91
92       #include <libmseed.h>
93
94       void log_print (const char *message);
95       void diag_print (const char *message);
96
97       main () {
98         ms_loginit (&log_print, "LOG: ", &diag_print, "ERR: ");
99
100         /* Normal log message, "LOG: " will be prefixed */
101         ms_log (0, "Normal log message for %s0, argv[0]);
102
103         /* Diognostic message, "LOG: " will be prefixed */
104         ms_log (1, "Diagnositc message for %s0, argv[0]);
105
106         /* Error message, "ERR: " will be prefixed */
107         ms_log (2, "Error message for %s0, argv[0]);
108       }
109
110       void log_print (const char *message) {
111         /* Send message to external log message facility */
112         send_log(message);
113       }
114
115       void diag_print (const char *message) {
116         /* Send message to external error message facility */
117         send_error(message);
118       }
119
120

AUTHOR

122       Chad Trabant
123       IRIS Data Management Center
124
125
126
127                                  2014/07/16                         MS_LOG(3)
Impressum