annotate libfdproto/msg_log.c @ 761:99625152176b

Remove message logging if the level is NONE
author Sebastien Decugis <sdecugis@nict.go.jp>
date Thu, 06 Oct 2011 20:55:48 +0200
parents 4a9f08d6b6ba
children edbdb35a603f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
689
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
1 /*********************************************************************************************************
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
2 * Software License Agreement (BSD License) *
740
4a9f08d6b6ba Updated my mail address
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 710
diff changeset
3 * Author: Sebastien Decugis <sdecugis@freediameter.net> *
689
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
4 * *
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
5 * Copyright (c) 2011, WIDE Project and NICT *
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
6 * All rights reserved. *
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
7 * *
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
8 * Redistribution and use of this software in source and binary forms, with or without modification, are *
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
9 * permitted provided that the following conditions are met: *
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
10 * *
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
11 * * Redistributions of source code must retain the above *
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
12 * copyright notice, this list of conditions and the *
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
13 * following disclaimer. *
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
14 * *
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
15 * * Redistributions in binary form must reproduce the above *
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
16 * copyright notice, this list of conditions and the *
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
17 * following disclaimer in the documentation and/or other *
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
18 * materials provided with the distribution. *
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
19 * *
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
20 * * Neither the name of the WIDE Project or NICT nor the *
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
21 * names of its contributors may be used to endorse or *
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
22 * promote products derived from this software without *
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
23 * specific prior written permission of WIDE Project and *
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
24 * NICT. *
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
25 * *
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED *
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
27 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
28 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR *
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
29 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
30 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS *
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR *
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
32 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF *
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
33 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
34 *********************************************************************************************************/
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
35
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
36 /* messages logging facility */
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
37 #include "fdproto-internal.h"
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
38 #include <stdarg.h>
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
39
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
40 /* Configuration of this module */
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
41 static struct {
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
42 struct {
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
43 enum fd_msg_log_method meth;
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
44 const char * metharg;
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
45 } causes[FD_MSG_LOG_MAX + 1];
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
46 pthread_mutex_t lock;
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
47 int init;
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
48 struct dictionary *dict;
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
49 } ml_conf = { .lock = PTHREAD_MUTEX_INITIALIZER, .init = 0 };
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
50
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
51
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
52 /* Initialize the module, with a dictionary to use to better parse the messages */
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
53 void fd_msg_log_init(struct dictionary *dict)
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
54 {
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
55 memset(&ml_conf.causes, 0, sizeof(ml_conf.causes));
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
56 ml_conf.init = 1;
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
57 ml_conf.dict = dict;
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
58 }
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
59
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
60 /* Set a configuration property */
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
61 int fd_msg_log_config(enum fd_msg_log_cause cause, enum fd_msg_log_method method, const char * arg)
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
62 {
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
63 /* Check the parameters are valid */
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
64 TRACE_ENTRY("%d %d %p", cause, method, arg);
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
65 CHECK_PARAMS( (cause >= 0) && (cause <= FD_MSG_LOG_MAX) );
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
66 CHECK_PARAMS( (method >= FD_MSG_LOGTO_DEBUGONLY) && (method <= FD_MSG_LOGTO_DIR) );
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
67 CHECK_PARAMS( (method == FD_MSG_LOGTO_DEBUGONLY) || (arg != NULL) );
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
68
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
69 /* Lock the configuration */
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
70 CHECK_POSIX( pthread_mutex_lock(&ml_conf.lock) );
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
71 if (!ml_conf.init) {
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
72 ASSERT(0);
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
73 }
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
74
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
75 /* Now set the parameter */
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
76 ml_conf.causes[cause].meth = method;
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
77 ml_conf.causes[cause].metharg = arg;
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
78
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
79 if (method) {
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
80 TRACE_DEBUG(INFO, "Logging %s messages set to %s '%s'",
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
81 (cause == FD_MSG_LOG_DROPPED) ? "DROPPED" :
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
82 (cause == FD_MSG_LOG_RECEIVED) ? "RECEIVED" :
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
83 (cause == FD_MSG_LOG_SENT) ? "SENT" :
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
84 "???",
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
85 (method == FD_MSG_LOGTO_FILE) ? "file" :
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
86 (method == FD_MSG_LOGTO_DIR) ? "directory" :
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
87 "???",
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
88 arg);
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
89 }
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
90
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
91 CHECK_POSIX( pthread_mutex_unlock(&ml_conf.lock) );
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
92
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
93 /* Done */
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
94 return 0;
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
95 }
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
96
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
97 /* Do not log anything within this one, since log lock is held */
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
98 static void fd_cleanup_mutex_silent( void * mutex )
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
99 {
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
100 (void)pthread_mutex_unlock((pthread_mutex_t *)mutex);
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
101 }
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
102
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
103 /* Really log the message */
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
104 void fd_msg_log( enum fd_msg_log_cause cause, struct msg * msg, const char * prefix_format, ... )
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
105 {
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
106 va_list ap;
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
107 enum fd_msg_log_method meth;
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
108 const char * metharg;
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
109 FILE * fstr;
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
110
710
e60376cb15e8 Minor changes
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 689
diff changeset
111 char buftime[256];
e60376cb15e8 Minor changes
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 689
diff changeset
112 size_t offset = 0;
e60376cb15e8 Minor changes
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 689
diff changeset
113 struct timespec ts;
e60376cb15e8 Minor changes
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 689
diff changeset
114 struct tm tm;
e60376cb15e8 Minor changes
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 689
diff changeset
115
689
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
116 TRACE_ENTRY("%d %p %p", cause, msg, prefix_format);
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
117 CHECK_PARAMS_DO( (cause >= 0) && (cause <= FD_MSG_LOG_MAX),
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
118 {
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
119 TRACE_DEBUG(INFO, "Invalid cause received (%d)! Message was:", cause);
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
120 fd_msg_dump_walk(INFO, msg);
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
121 } );
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
122
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
123 /* First retrieve the config for this message */
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
124 CHECK_POSIX_DO( pthread_mutex_lock(&ml_conf.lock), );
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
125 if (!ml_conf.init) {
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
126 ASSERT(0);
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
127 }
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
128 meth = ml_conf.causes[cause].meth;
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
129 metharg = ml_conf.causes[cause].metharg;
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
130 CHECK_POSIX_DO( pthread_mutex_unlock(&ml_conf.lock), );
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
131
761
99625152176b Remove message logging if the level is NONE
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 740
diff changeset
132 /* Do not log if the level is not at least INFO */
99625152176b Remove message logging if the level is NONE
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 740
diff changeset
133 if ((meth == FD_MSG_LOGTO_DEBUGONLY) && (fd_g_debug_lvl < INFO)) {
99625152176b Remove message logging if the level is NONE
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 740
diff changeset
134 return;
99625152176b Remove message logging if the level is NONE
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 740
diff changeset
135 }
99625152176b Remove message logging if the level is NONE
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 740
diff changeset
136
710
e60376cb15e8 Minor changes
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 689
diff changeset
137 /* Get current time */
e60376cb15e8 Minor changes
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 689
diff changeset
138 CHECK_SYS_DO( clock_gettime(CLOCK_REALTIME, &ts), /* continue */);
e60376cb15e8 Minor changes
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 689
diff changeset
139 offset += strftime(buftime + offset, sizeof(buftime) - offset, "%D,%T", localtime_r( &ts.tv_sec , &tm ));
e60376cb15e8 Minor changes
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 689
diff changeset
140 offset += snprintf(buftime + offset, sizeof(buftime) - offset, ".%6.6ld", ts.tv_nsec / 1000);
e60376cb15e8 Minor changes
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 689
diff changeset
141
e60376cb15e8 Minor changes
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 689
diff changeset
142
689
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
143 /* Okay, now we will create the file descriptor */
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
144 switch (meth) {
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
145 case FD_MSG_LOGTO_DEBUGONLY:
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
146 fstr = fd_g_debug_fstr;
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
147 break;
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
148
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
149 case FD_MSG_LOGTO_FILE:
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
150 TODO("Log to arg file");
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
151 TODO("Log a note to debug stream");
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
152 break;
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
153 case FD_MSG_LOGTO_DIR:
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
154 TODO("Log to arg directory in a new file");
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
155 TODO("Log a note to debug stream");
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
156 break;
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
157 }
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
158
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
159 /* For file methods, let's parse the message so it looks better */
710
e60376cb15e8 Minor changes
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 689
diff changeset
160 if (((meth != FD_MSG_LOGTO_DEBUGONLY) || (fd_g_debug_lvl > FULL)) && ml_conf.dict) {
689
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
161 CHECK_FCT_DO( fd_msg_parse_dict( msg, ml_conf.dict, NULL ), );
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
162 }
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
163
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
164 /* Then dump the prefix message to this stream, & to debug stream */
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
165 (void)pthread_mutex_lock(&fd_log_lock);
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
166 pthread_cleanup_push(fd_cleanup_mutex_silent, &fd_log_lock);
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
167 va_start(ap, prefix_format);
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
168 vfprintf( fstr, prefix_format, ap);
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
169 va_end(ap);
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
170 fflush(fstr);
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
171 pthread_cleanup_pop(0);
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
172 (void)pthread_mutex_unlock(&fd_log_lock);
710
e60376cb15e8 Minor changes
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 689
diff changeset
173
e60376cb15e8 Minor changes
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 689
diff changeset
174 fd_log_debug_fstr(fstr, "\nLogged: %s\n\n", buftime);
689
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
175
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
176 /* And now the message itself */
710
e60376cb15e8 Minor changes
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 689
diff changeset
177 if ((meth == FD_MSG_LOGTO_DEBUGONLY) && (fd_g_debug_lvl <= INFO)) {
e60376cb15e8 Minor changes
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 689
diff changeset
178 /* dump only the header */
e60376cb15e8 Minor changes
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 689
diff changeset
179 fd_msg_dump_fstr_one(msg, fstr);
e60376cb15e8 Minor changes
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 689
diff changeset
180 } else {
e60376cb15e8 Minor changes
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 689
diff changeset
181 /* dump the full content */
e60376cb15e8 Minor changes
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 689
diff changeset
182 fd_msg_dump_fstr(msg, fstr);
e60376cb15e8 Minor changes
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 689
diff changeset
183 }
689
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
184
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
185 /* And finally close the stream if needed */
710
e60376cb15e8 Minor changes
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 689
diff changeset
186 switch (meth) {
e60376cb15e8 Minor changes
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 689
diff changeset
187 case FD_MSG_LOGTO_DEBUGONLY:
e60376cb15e8 Minor changes
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 689
diff changeset
188 break;
e60376cb15e8 Minor changes
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 689
diff changeset
189
e60376cb15e8 Minor changes
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 689
diff changeset
190 case FD_MSG_LOGTO_FILE:
e60376cb15e8 Minor changes
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 689
diff changeset
191 TODO("close?");
e60376cb15e8 Minor changes
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 689
diff changeset
192 break;
e60376cb15e8 Minor changes
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 689
diff changeset
193 case FD_MSG_LOGTO_DIR:
e60376cb15e8 Minor changes
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 689
diff changeset
194 TODO("close?");
e60376cb15e8 Minor changes
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 689
diff changeset
195 break;
e60376cb15e8 Minor changes
Sebastien Decugis <sdecugis@nict.go.jp>
parents: 689
diff changeset
196 }
689
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
197 }
933d098fc75d Cleanups in msg_log feature
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff changeset
198
"Welcome to our mercurial repository"