Merge lp:~fahad-aizaz/hipl/logging into lp:hipl

Proposed by Fahad Aizaz
Status: Rejected
Rejected by: René Hummen
Proposed branch: lp:~fahad-aizaz/hipl/logging
Merge into: lp:hipl
Diff against target: 318 lines (+83/-32)
9 files modified
firewall/main.c (+2/-0)
hipd/hipd.c (+4/-4)
hipd/init.c (+1/-1)
hipd/user.c (+6/-0)
lib/core/builder.c (+1/-0)
lib/core/conf.c (+8/-3)
lib/core/debug.c (+57/-12)
lib/core/debug.h (+3/-12)
lib/core/icomm.h (+1/-0)
To merge this branch: bzr merge lp:~fahad-aizaz/hipl/logging
Reviewer Review Type Date Requested Status
René Hummen Disapprove
Stefan Götz (community) Needs Fixing
Diego Biurrun Needs Information
Miika Komu Pending
Review via email: mp+65788@code.launchpad.net

This proposal supersedes a proposal from 2011-06-09.

Description of the change

The SYSLOG functionality has been added. A new logdebug level has been added.

HIP daemon is now configured so that when it is executed in background mode: all the debug messages are logged into the syslog. The configuration file for syslog which dictates what and how messages are suppose to be logged can be altered to user requirement. If the HIP daemon is executed in the foreground mode then in that case all the messages are logged both on STDERR and SYSLOG.

NOTE: HIP uses FACILITY = LOG_LOCAL6; which can be used in syslog configuration file.

A new logdebug level LOGDEBUG_LOW has been added to the debug levels in which the application can operate. i.e. (NONE, LOW, MEDIUM, ALL); The following matrix describes what kind of messages will be displayed based on selection of logdebug
=================================
| NONE | DIE, ASSERT
---------------------------------
| LOW | DIE, ASSERT, ERROR
---------------------------------
| MEDIUM | DIE, ASSERT, ERROR, INFO
---------------------------------
| ALL | DIE, ASSERT, ERROR, INFO, DEBUG
================================

The debug level at which the application can be executed is either hardcoded or otherwise selected
by the debug switch chosen when the application is executed.

NOTE: In case of HIP, in the end it is the debug level set in the configuration file of hip daemon
"hipd_config" that dictates which debug level the application must execute.

========================
Removed the conflicts. Required review again

To post a comment you must log in.
Revision history for this message
Stefan Götz (stefan.goetz-deactivatedaccount) wrote : Posted in a previous version of this proposal

Hi Fahad!

Nice feature. Please take care of the merge conflicts with trunk and resubmit the merge proposal.

Cheers,
      Stefan

review: Needs Resubmitting
Revision history for this message
Miika Komu (miika-iki) wrote : Posted in a previous version of this proposal

> If the HIP daemon is executed in the foreground mode then in that case all the messages are
> logged both on STDERR and SYSLOG.

I don't see why somebody would want to do this? I mean if you run it on the foreground, then I would expect everything to happen on the foreground. If grepping is needed, then normal shell redirection and pipes tricks apply. Can you find some other daemon software that does this?

You're missing some documentation:
* lib/core/conf.c:hipconf_usage
* doc/HOWTO.xml (grep "debug all")
* doc/HACKING:DEBUGGING

If this gets merged (in a form or another) at some point, please add a note about LOG_LOCAL6 to here:

https://bugs.launchpad.net/hipl/+bug/592157

review: Needs Information
Revision history for this message
Diego Biurrun (diego-biurrun) wrote : Posted in a previous version of this proposal

This has unrelated changes and does not even compile as it contains merge conflicts.

What is it with submitting merge proposals that contain merge conflicts? Of course it is a bug that
bzr and/or launchpad accept them at all, but still, why is this not noticed? This is not the first time this happens so obviously (some of) our processes need to get fixed.

review: Needs Fixing
Revision history for this message
Fahad Aizaz (fahad-aizaz) wrote : Posted in a previous version of this proposal

Hi Miika,

I discussed your point with Rene and he explained to me that this feature is required in case of remote logging. i.e. while the process is executed in foreground, the debug output will still be logged at the remote (syslog) server.

I am going to update the information, in the files you mentioned above. LOCAL6 does provide a facility to seggregate the log for a specific process into files. I think there also a way where the same LOCAL6 option can be used to differentiate the two processes using the same constant. (in our case both PISA AND HIPL use the LOCAL6 constant)

> > If the HIP daemon is executed in the foreground mode then in that case all
> the messages are
> > logged both on STDERR and SYSLOG.
>
> I don't see why somebody would want to do this? I mean if you run it on the
> foreground, then I would expect everything to happen on the foreground. If
> grepping is needed, then normal shell redirection and pipes tricks apply. Can
> you find some other daemon software that does this?
>
> You're missing some documentation:
> * lib/core/conf.c:hipconf_usage
> * doc/HOWTO.xml (grep "debug all")
> * doc/HACKING:DEBUGGING
>
> If this gets merged (in a form or another) at some point, please add a note
> about LOG_LOCAL6 to here:
>
> https://bugs.launchpad.net/hipl/+bug/592157

Revision history for this message
Fahad Aizaz (fahad-aizaz) wrote : Posted in a previous version of this proposal

I will fix the conflicts and propose merge again. I am new with bzr/launchpad and didn't notice the conflicts.

> This has unrelated changes and does not even compile as it contains merge
> conflicts.
>
> What is it with submitting merge proposals that contain merge conflicts? Of
> course it is a bug that
> bzr and/or launchpad accept them at all, but still, why is this not noticed?
> This is not the first time this happens so obviously (some of) our processes
> need to get fixed.

Revision history for this message
Diego Biurrun (diego-biurrun) wrote :
Download full text (6.1 KiB)

 review needs-info

On Fri, Jun 24, 2011 at 01:38:15PM +0000, Fahad Aizaz wrote:
>
> For more details, see:
> https://code.launchpad.net/~fahad-aizaz/hipl/logging/+merge/65788
>
> The SYSLOG functionality has been added. A new logdebug level has been added.

IMO these are two independent things that should really be reviewed
and decided upon separately in two independent merge proposals.

> --- firewall/main.c 2011-06-22 13:25:54 +0000
> +++ firewall/main.c 2011-06-24 13:38:10 +0000
> @@ -230,6 +230,8 @@
> if (fork() > 0) {
> return EXIT_SUCCESS;
> }
> + } else {
> + hip_set_logtype(LOGTYPE_STDERR_SYSLOG);
> }
>
> --- hipd/hipd.c 2011-05-16 11:39:06 +0000
> +++ hipd/hipd.c 2011-06-24 13:38:10 +0000
> @@ -165,7 +165,7 @@
> fprintf(stderr, " -f set debug type format to short\n");
> - fprintf(stderr, " -d set the initial (pre-config) debug level to ALL (default is MEDIUM)\n");
> + fprintf(stderr, " -d set the initial (pre-config) debug level to ALL (default is LOW)\n");
> fprintf(stderr, " -D <module name> disable this module. " \
> "Use additional -D for additional modules.\n");
> @@ -326,7 +326,7 @@
>
> /* Configuration is valid! Fork a daemon, if so configured */
> if (flags & HIPD_START_FOREGROUND) {
> - hip_set_logtype(LOGTYPE_STDERR);
> + hip_set_logtype(LOGTYPE_STDERR_SYSLOG);
> HIP_DEBUG("foreground\n");
> } else {
> hip_set_logtype(LOGTYPE_SYSLOG);
> @@ -446,7 +446,7 @@
>
> /* set the initial verbosity level */
> - hip_set_logdebug(LOGDEBUG_MEDIUM);
> + hip_set_logdebug(LOGDEBUG_LOW);
>
> @@ -457,7 +457,7 @@
>
> /* We need to recreate the NAT UDP sockets to bind to the new port. */
> if (getuid()) {
> - HIP_ERROR("hipd must be started as root!\n");
> + HIP_DIE("hipd must be started as root!\n");
> return EXIT_FAILURE;

I wonder why this is so different between hipfw and hipd.

> --- hipd/user.c 2011-05-16 11:39:06 +0000
> +++ hipd/user.c 2011-06-24 13:38:10 +0000
> @@ -335,6 +335,12 @@
> HIP_IFEL(hip_set_logdebug(LOGDEBUG_MEDIUM), -1,
> "Error when setting daemon DEBUG status to MEDIUM\n");
> break;
> + case HIP_MSG_SET_DEBUG_LOW:
> + /* Removes debugging messages. */
> + HIP_DEBUG("Handling DEBUG LOW user message.\n");
> + HIP_IFEL(hip_set_logdebug(LOGDEBUG_LOW), -1,
> + "Error when setting daemon DEBUG status to LOW\n");
> + break;
> case HIP_MSG_SET_DEBUG_NONE:
> /* Removes debugging messages. */
> HIP_DEBUG("Handling DEBUG NONE user message.\n");

The comment seems to make no sense but rather looks like it was blindly
copy-pasted from below.

> --- lib/core/debug.c 2011-04-05 16:44:22 +0000
> +++ lib/core/debug.c 2011-06-24 13:38:10 +0000
> @@ -216,13 +228,14 @@
> case LOGTYPE_NOLOG:
> break;
> case LOGTYPE_STDERR:
> - if (strlen(prefix) > 0) {
> +
> + if (strlen(prefix)) {
> printed = fprintf(stderr, "%s: ", prefix);

Why?

> if (printed < 0) {
> goto err;
> ...

Read more...

review: Needs Information
Revision history for this message
Stefan Götz (stefan.goetz-deactivatedaccount) wrote :
Download full text (3.5 KiB)

Hi Fahad!

> === modified file 'hipd/hipd.c'

Please don't forget to update the Copyright dates when you modify files with
Copyright headers. Scatterbrains like myself may want to try out the pre-commit
hook in https://code.launchpad.net/~stefan.goetz/hipl/commitguard that
automatically checks for that.

> /* We need to recreate the NAT UDP sockets to bind to the new port. */
> if (getuid()) {
> - HIP_ERROR("hipd must be started as root!\n");
> + HIP_DIE("hipd must be started as root!\n");
> return EXIT_FAILURE;
> }

[L] Does this change really belong into this branch? It changes the behavior of hipd in a way that is not relate to logging policy.

> === modified file 'hipd/user.c'

Please don't forget to update the Copyright dates when you modify files with
Copyright headers. Scatterbrains like myself may want to try out the pre-commit
hook in https://code.launchpad.net/~stefan.goetz/hipl/commitguard that
automatically checks for that.

> === modified file 'lib/core/conf.c'
> + * @param debug all contains a new option "low" which includes messages
> + * with priority die/assert and error.

[M] Please remove 'new' here - once this code is committed, the option is no longer new and it's irrelevant whether it is new or not, anyway.

> === modified file 'lib/core/debug.c'
> --- lib/core/debug.c 2011-04-05 16:44:22 +0000
> +++ lib/core/debug.c 2011-06-24 13:38:10 +0000
> @@ -139,6 +139,18 @@
> */
> void hip_set_logtype(int new_logtype)

[L] policy: for boyscouting, it would be nice to make 'new_logtype' 'const'. Also, it should be of type 'enum logtype'.

> @@ -216,13 +228,14 @@
> case LOGTYPE_NOLOG:
> break;
> case LOGTYPE_STDERR:
> - if (strlen(prefix) > 0) {
> +
> + if (strlen(prefix)) {

[L] This change is ok, but then, I don't see the point of it.

> } else {
> - /* LOGFMT_SHORT: no prefix */
> + // LOGFMT_SHORT: no prefix

[L] same - this cosmetic cleanup has nothing to do with this branch

> === modified file 'lib/core/debug.h'
> --- lib/core/debug.h 2011-01-10 15:13:47 +0000
> +++ lib/core/debug.h 2011-06-24 13:38:10 +0000
> @@ -233,7 +233,7 @@
> * messed up. You can find the implementation of these macros from lib/core/debug.h.
> * @{
> */
> -#ifdef CONFIG_HIP_DEBUG
> +
> #define HIP_DEBUG(...) hip_print_str(DEBUG_LEVEL_DEBUG, __FILE__, __LINE__, __FUNCTION__, __VA_ARGS__)
> #define HIP_HEXDUMP(prefix, str, len) \
> hip_hexdump(__FILE__, __LINE__, __FUNCTION__, prefix, str, len)
> @@ -245,15 +245,6 @@
> #define HIP_DEBUG_GL(debug_group, debug_level, ...) \
> hip_debug_gl(debug_group, debug_level, __FILE__, __LINE__, __FUNCTION__, __VA_ARGS__)
>
> -#else
> -#define HIP_DEBUG(...) do {} while (0)
> -#define HIP_HEXDUMP(prefix, str, len) do {} while (0)
> -#define HIP_DUMP_PACKET(prefix, str, len) do {} while (0)
> -#define HIP_DEBUG_SOCKADDR(prefix, sockaddr) do {} while (0)
> -#define HIP_DUMP_MSG(msg) do {} while (0)
> -#define HIP_DEBUG_GL(debug_group, debug_level, ...) do {} while (0)
> -#endif
> -

[L] Is it really necessary to remove the facility to completely disable debug output? I believe th...

Read more...

review: Needs Fixing
Revision history for this message
Stefan Götz (stefan.goetz-deactivatedaccount) wrote :

What's the status of this proposal? It has been dormant for 6 months now. Are the reasons against deleting it?

Revision history for this message
René Hummen (rene-hummen) wrote :

We merged the functional changes that everybody agreed on in a separate branch already. This branch is not required any further.

review: Disapprove

Unmerged revisions

5978. By Fahad Aizaz

Updated the documentation about debugging parameters

5977. By Fahad Aizaz

Handling of LOGDEBUG_LOW (debug level) updated

After adding the support for debug level messages LOGDEBUG_LOW to debug.c
and debug.h and its functionality in hip daemon, is now extended to other
files that were using the LOGDEBUG.

So now if LOGDEBUG_LOW is required by other modules, it can be used since
its support has been added to the project.

NOTE: LOGDEBUG levels are (NONE, LOW, MEDIUM, ALL). The messages with
debug_level (DIE/ASSERT, ERROR, INFO, DEBUG) are displayed on STDERR,
STDERR and SYSLOG, or SYSLOG only depends on the selection of LOGDEBUG
level either by (hardcoded) using in the application or in the
configuration file. Other than that the debug switch applied at the
execution of hip daemon, retains its effect until the configuration file
is read and the daemon is set according to the settings in the
configuration file.

5976. By Fahad Aizaz

Updated comment for logdebug and debug_level

Mistake in the comment is rectified

5975. By Fahad Aizaz

LOGDEBUG levels have been updated to accomodate a new level

A new level LOGDEBUG_LOW has been added to the enumeration of logdebug
enum logdebug {LOGDEBUG_ALL,LOGDEBUG_MEDIUM,LOGDEBUG_LOW,LOGDEBUG_NONE};

The logdebug enum selects the type of messages (error messages that can
be displayed (die, assert, error, info, debug)
Following matrix shows the type of messages that can displayed at each
level:
====================================================
| logdebug | debug_level (of messages) |
----------------------------------------------------
| NONE | DIE/ASSERT |
----------------------------------------------------
| LOW | DIE/ASSERT, ERROR |
----------------------------------------------------
| MEDIUM | DIE/ASSERT, ERROR, INFO |
----------------------------------------------------
| ALL | DIE/ASSERT, ERROR, INFO, DEBUG |
====================================================

NOTE: hip daemon now starts with the logdebug = LOW; i.e. only the
die, assert and error messages are displayed.

5974. By Fahad Aizaz

Default behaviour for logging in Test mode and Production mode.

This updates marks that the default behaviour for logging in both
test mode and production mode will be the same i.e. logging will be
in either form

5973. By Fahad Aizaz

SYSLOG functionality extended

The debug messages (info, error, debug etc) has been now placed both
on console and syslog based on the switch used to execute hipd i.e.
if hipd is executed in background mode then all the error messages
will be placed into syslog only otherwise the error messages will be
displayed on console window and also stored to syslog.

An additional switch has been added: LOGTYPE_STDERR_SYSLOG which
identifies whether messages need to be placed both on stderr & syslog
or not. Also the default functionality of the application with regard
to logging error messages has been changed. Now whether application
executed in production mode or testing mode, in both cases error
messages will be logged.

Usage:
And process that needs to use this fuctionality simply has to set the
logtype to the desired option: e.g. logtype = LOGTYPE_SYSLOG

NOTE:
This is hardcoded functionality i.e. all daemon processes log into
syslog and all foreground processes log error messages to console and
syslog.

SYSLOG facility that is used is: LOCAL6
Using LOCAL6 enables the localized logging for error messages. This can
be achived by configuring unix/linux syslog configuration.
e.g. local6.* -/var/log/hip.log
will log all messages from the processes using the facility LOCAL6
into hip.log file.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'firewall/main.c'
2--- firewall/main.c 2011-06-22 13:25:54 +0000
3+++ firewall/main.c 2011-06-24 13:38:10 +0000
4@@ -230,6 +230,8 @@
5 if (fork() > 0) {
6 return EXIT_SUCCESS;
7 }
8+ } else {
9+ hip_set_logtype(LOGTYPE_STDERR_SYSLOG);
10 }
11
12 return hipfw_main(rule_file, kill_old, limit_capabilities) == 0
13
14=== modified file 'hipd/hipd.c'
15--- hipd/hipd.c 2011-05-16 11:39:06 +0000
16+++ hipd/hipd.c 2011-06-24 13:38:10 +0000
17@@ -165,7 +165,7 @@
18 fprintf(stderr, " -N do not flush all IPsec databases during start\n");
19 fprintf(stderr, " -a fix alignment issues automatically(ARM)\n");
20 fprintf(stderr, " -f set debug type format to short\n");
21- fprintf(stderr, " -d set the initial (pre-config) debug level to ALL (default is MEDIUM)\n");
22+ fprintf(stderr, " -d set the initial (pre-config) debug level to ALL (default is LOW)\n");
23 fprintf(stderr, " -D <module name> disable this module. " \
24 "Use additional -D for additional modules.\n");
25 fprintf(stderr, " -p disable privilege separation\n");
26@@ -326,7 +326,7 @@
27
28 /* Configuration is valid! Fork a daemon, if so configured */
29 if (flags & HIPD_START_FOREGROUND) {
30- hip_set_logtype(LOGTYPE_STDERR);
31+ hip_set_logtype(LOGTYPE_STDERR_SYSLOG);
32 HIP_DEBUG("foreground\n");
33 } else {
34 hip_set_logtype(LOGTYPE_SYSLOG);
35@@ -446,7 +446,7 @@
36 sflags |= HIPD_START_LOAD_KMOD;
37
38 /* set the initial verbosity level */
39- hip_set_logdebug(LOGDEBUG_MEDIUM);
40+ hip_set_logdebug(LOGDEBUG_LOW);
41
42 /* One should be able to check the hipd version and usage,
43 * even without having root privileges.
44@@ -457,7 +457,7 @@
45
46 /* We need to recreate the NAT UDP sockets to bind to the new port. */
47 if (getuid()) {
48- HIP_ERROR("hipd must be started as root!\n");
49+ HIP_DIE("hipd must be started as root!\n");
50 return EXIT_FAILURE;
51 }
52
53
54=== modified file 'hipd/init.c'
55--- hipd/init.c 2011-05-04 16:20:00 +0000
56+++ hipd/init.c 2011-06-24 13:38:10 +0000
57@@ -184,7 +184,7 @@
58 nat plain-udp # use UDP capsulation (for NATted environments)\n\
59 #nat port local 11111 # change local default UDP port\n\
60 #nat port peer 22222 # change local peer UDP port\n\
61-debug medium # debug verbosity: all, medium or none\n"
62+debug medium # debug verbosity: all, medium, low or none\n"
63
64 #define HIPL_HOSTS_FILE_EX \
65 "# This file stores the HITs of the hosts, in a similar fashion to /etc/hosts.\n\
66
67=== modified file 'hipd/user.c'
68--- hipd/user.c 2011-05-16 11:39:06 +0000
69+++ hipd/user.c 2011-06-24 13:38:10 +0000
70@@ -335,6 +335,12 @@
71 HIP_IFEL(hip_set_logdebug(LOGDEBUG_MEDIUM), -1,
72 "Error when setting daemon DEBUG status to MEDIUM\n");
73 break;
74+ case HIP_MSG_SET_DEBUG_LOW:
75+ /* Removes debugging messages. */
76+ HIP_DEBUG("Handling DEBUG LOW user message.\n");
77+ HIP_IFEL(hip_set_logdebug(LOGDEBUG_LOW), -1,
78+ "Error when setting daemon DEBUG status to LOW\n");
79+ break;
80 case HIP_MSG_SET_DEBUG_NONE:
81 /* Removes debugging messages. */
82 HIP_DEBUG("Handling DEBUG NONE user message.\n");
83
84=== modified file 'lib/core/builder.c'
85--- lib/core/builder.c 2011-05-16 11:39:06 +0000
86+++ lib/core/builder.c 2011-06-24 13:38:10 +0000
87@@ -1115,6 +1115,7 @@
88 case HIP_MSG_CONF_PUZZLE_DEC: return "HIP_MSG_CONF_PUZZLE_DEC";
89 case HIP_MSG_SET_DEBUG_ALL: return "HIP_MSG_SET_DEBUG_ALL";
90 case HIP_MSG_SET_DEBUG_MEDIUM: return "HIP_MSG_SET_DEBUG_MEDIUM";
91+ case HIP_MSG_SET_DEBUG_LOW: return "HIP_MSG_SET_DEBUG_LOW";
92 case HIP_MSG_SET_DEBUG_NONE: return "HIP_MSG_SET_DEBUG_NONE";
93 case HIP_MSG_SET_LOCATOR_ON: return "HIP_MSG_SET_LOCATOR_ON";
94 case HIP_MSG_SET_LOCATOR_OFF: return "HIP_MSG_SET_LOCATOR_OFF";
95
96=== modified file 'lib/core/conf.c'
97--- lib/core/conf.c 2011-06-09 17:19:33 +0000
98+++ lib/core/conf.c 2011-06-24 13:38:10 +0000
99@@ -223,7 +223,7 @@
100 "\tdel server rvs|relay|full-relay [HIT] <IP|hostname>\n"
101 "heartbeat <seconds> (0 seconds means off)\n"
102 "locator on|off|get\n"
103- "debug all|medium|none\n"
104+ "debug all|medium|low|none\n"
105 "transform order <integer> "
106 " (1=AES, 2=3DES, 3=NULL and place them to order\n"
107 " like 213 for the order 3DES, AES and NULL)\n"
108@@ -244,6 +244,8 @@
109 * @param optc currently unused
110 * @param send_only 1 if no response from hipd should be requrested, or 0 if
111 * should block for a response from hipd
112+ * @param debug all contains a new option "low" which includes messages
113+ * with priority die/assert and error.
114 * @return zero for success and negative on error
115 */
116 static int hip_get_hits(struct hip_common *msg, const char *opt,
117@@ -1502,7 +1504,7 @@
118 int status = 0;
119
120 if (optc != 0) {
121- HIP_ERROR("Wrong number of arguments. Usage:\nhipconf debug all|medium|none\n");
122+ HIP_ERROR("Wrong number of arguments. Usage:\nhipconf debug all|medium|low|none\n");
123 return -EINVAL;
124 }
125
126@@ -1510,8 +1512,11 @@
127 HIP_INFO("Displaying all debugging messages\n");
128 status = HIP_MSG_SET_DEBUG_ALL;
129 } else if (!strcmp("medium", opt[0])) {
130- HIP_INFO("Displaying ERROR and INFO debugging messages\n");
131+ HIP_INFO("Displaying INFO debugging messages\n");
132 status = HIP_MSG_SET_DEBUG_MEDIUM;
133+ } else if (!strcmp("low", opt[0])) {
134+ HIP_INFO("Displaying ERROR debugging messages\n");
135+ status = HIP_MSG_SET_DEBUG_LOW;
136 } else if (!strcmp("none", opt[0])) {
137 HIP_INFO("Displaying no debugging messages\n");
138 status = HIP_MSG_SET_DEBUG_NONE;
139
140=== modified file 'lib/core/debug.c'
141--- lib/core/debug.c 2011-04-05 16:44:22 +0000
142+++ lib/core/debug.c 2011-06-24 13:38:10 +0000
143@@ -139,6 +139,18 @@
144 */
145 void hip_set_logtype(int new_logtype)
146 {
147+ switch (new_logtype) {
148+ case LOGTYPE_NOLOG:
149+ break;
150+ case LOGTYPE_SYSLOG:
151+ openlog(NULL, (LOG_PID | LOG_CONS), SYSLOG_FACILITY);
152+ break;
153+ case LOGTYPE_STDERR:
154+ break;
155+ case LOGTYPE_STDERR_SYSLOG:
156+ openlog(NULL, (LOG_PID | LOG_PERROR | LOG_CONS), SYSLOG_FACILITY);
157+ break;
158+ }
159 logtype = new_logtype;
160 }
161
162@@ -158,7 +170,7 @@
163 /**
164 * @brief Selects what logging messages to display.
165 *
166- * @param new_logdebug either LOGDEBUG_ALL, LOGDEBUG_MEDIUM or LOGDEBUG_NONE
167+ * @param new_logdebug either LOGDEBUG_ALL, LOGDEBUG_MEDIUM, LOGDEBUG_LOW or LOGDEBUG_NONE
168 * @return always zero.
169 */
170 int hip_set_logdebug(int new_logdebug)
171@@ -216,13 +228,14 @@
172 case LOGTYPE_NOLOG:
173 break;
174 case LOGTYPE_STDERR:
175- if (strlen(prefix) > 0) {
176+
177+ if (strlen(prefix)) {
178 printed = fprintf(stderr, "%s: ", prefix);
179 if (printed < 0) {
180 goto err;
181 }
182 } else {
183- /* LOGFMT_SHORT: no prefix */
184+ // LOGFMT_SHORT: no prefix
185 }
186
187 printed = vfprintf(stderr, fmt, args);
188@@ -230,25 +243,39 @@
189 goto err;
190 }
191 break;
192+ case LOGTYPE_STDERR_SYSLOG:
193+
194+ printed = vsnprintf(syslog_msg, DEBUG_MSG_MAX_LEN, fmt, args);
195+ if (strlen(prefix)) {
196+ syslog(syslog_level | SYSLOG_FACILITY, "%s %s", prefix, syslog_msg);
197+ } else {
198+ syslog(syslog_level | SYSLOG_FACILITY, "%s", syslog_msg);
199+ }
200+
201+ if (printed < 0) {
202+ goto err;
203+ }
204+ break;
205 case LOGTYPE_SYSLOG:
206- openlog(NULL, LOG_PID, SYSLOG_FACILITY);
207+
208 printed = vsnprintf(syslog_msg, DEBUG_MSG_MAX_LEN, fmt, args);
209 syslog(syslog_level | SYSLOG_FACILITY, "%s %s", prefix, syslog_msg);
210- /* the result of vsnprintf depends on glibc version; handle them both
211+ /**
212+ * the result of vsnprintf depends on glibc version; handle them both
213 * (note about barriers: printed has \0 excluded,
214- * DEBUG_MSG_MAX_LEN has \0 included) */
215+ * DEBUG_MSG_MAX_LEN has \0 included)
216+ */
217 if (printed < 0 || printed > DEBUG_MSG_MAX_LEN - 1) {
218 syslog(syslog_level | SYSLOG_FACILITY,
219- "%s", "previous msg was truncated!!!");
220+ "previous msg was truncated!!!");
221 }
222- closelog();
223 break;
224 default:
225 printed = fprintf(stderr, "hip_vlog(): undefined logtype: %d", logtype);
226 exit(1);
227 }
228
229- /* logging was succesful */
230+ /* logging was successful */
231 return;
232
233 err:
234@@ -276,10 +303,28 @@
235 {
236 va_list args;
237 va_start(args, fmt);
238- if ((debug_level == DEBUG_LEVEL_INFO && logdebug != LOGDEBUG_NONE) ||
239- (debug_level == DEBUG_LEVEL_DEBUG && logdebug == LOGDEBUG_ALL) ||
240+ /**
241+ * Following matrix is implemented below
242+ * ====================================================
243+ * | logdebug | debug_level |
244+ * ----------------------------------------------------
245+ * | NONE | DIE/ASSERT |
246+ * ----------------------------------------------------
247+ * | LOW | DIE/ASSERT, ERROR |
248+ * ----------------------------------------------------
249+ * | MEDIUM | DIE/ASSERT, ERROR, INFO |
250+ * ----------------------------------------------------
251+ * | ALL | DIE/ASSERT, ERROR, INFO, DEBUG |
252+ * ====================================================
253+ *
254+ * NOTE: HIP_ASSERT ==>> HIP_DIE (DEBUG_LEVEL_DIE);
255+ * HIP_HEXDUMP, HIP_DUMP_PACKET, HIP_DEBUG_SOCKADDR, HIP_DUMP_MSG ==>> HIP_DEBUG (DEBUG_LEVEL_DEBUG)
256+ */
257+
258+ if ((debug_level == DEBUG_LEVEL_DIE) ||
259 (debug_level == DEBUG_LEVEL_ERROR && logdebug != LOGDEBUG_NONE) ||
260- (debug_level == DEBUG_LEVEL_DIE)) {
261+ (debug_level == DEBUG_LEVEL_INFO && logdebug != LOGDEBUG_NONE && logdebug != LOGDEBUG_LOW) ||
262+ (debug_level == DEBUG_LEVEL_DEBUG && logdebug == LOGDEBUG_ALL)) {
263 hip_vlog(debug_level, file, line, function, fmt, args);
264 }
265 va_end(args);
266
267=== modified file 'lib/core/debug.h'
268--- lib/core/debug.h 2011-01-10 15:13:47 +0000
269+++ lib/core/debug.h 2011-06-24 13:38:10 +0000
270@@ -233,7 +233,7 @@
271 * messed up. You can find the implementation of these macros from lib/core/debug.h.
272 * @{
273 */
274-#ifdef CONFIG_HIP_DEBUG
275+
276 #define HIP_DEBUG(...) hip_print_str(DEBUG_LEVEL_DEBUG, __FILE__, __LINE__, __FUNCTION__, __VA_ARGS__)
277 #define HIP_HEXDUMP(prefix, str, len) \
278 hip_hexdump(__FILE__, __LINE__, __FUNCTION__, prefix, str, len)
279@@ -245,15 +245,6 @@
280 #define HIP_DEBUG_GL(debug_group, debug_level, ...) \
281 hip_debug_gl(debug_group, debug_level, __FILE__, __LINE__, __FUNCTION__, __VA_ARGS__)
282
283-#else
284-#define HIP_DEBUG(...) do {} while (0)
285-#define HIP_HEXDUMP(prefix, str, len) do {} while (0)
286-#define HIP_DUMP_PACKET(prefix, str, len) do {} while (0)
287-#define HIP_DEBUG_SOCKADDR(prefix, sockaddr) do {} while (0)
288-#define HIP_DUMP_MSG(msg) do {} while (0)
289-#define HIP_DEBUG_GL(debug_group, debug_level, ...) do {} while (0)
290-#endif
291-
292 /* @} */
293
294 /* Debug groups define groups of debug messages which belong to the
295@@ -297,9 +288,9 @@
296 #define HIP_DEBUG_LSI(str, lsi) HIP_PRINT(hip_print_lsi, DEBUG_LEVEL_DEBUG, str, lsi)
297 #define HIP_DEBUG_INADDR(str, in) HIP_DEBUG_LSI(str, in)
298
299-enum logtype { LOGTYPE_NOLOG, LOGTYPE_SYSLOG, LOGTYPE_STDERR };
300+enum logtype { LOGTYPE_NOLOG, LOGTYPE_SYSLOG, LOGTYPE_STDERR, LOGTYPE_STDERR_SYSLOG };
301 enum logfmt { LOGFMT_SHORT, LOGFMT_LONG };
302-enum logdebug { LOGDEBUG_ALL, LOGDEBUG_MEDIUM, LOGDEBUG_NONE };
303+enum logdebug { LOGDEBUG_ALL, LOGDEBUG_MEDIUM, LOGDEBUG_LOW, LOGDEBUG_NONE };
304
305 void hip_set_logtype(int logtype);
306 void hip_set_logfmt(int logfmt);
307
308=== modified file 'lib/core/icomm.h'
309--- lib/core/icomm.h 2011-05-16 11:39:06 +0000
310+++ lib/core/icomm.h 2011-06-24 13:38:10 +0000
311@@ -84,6 +84,7 @@
312 /* Free slots here */
313 #define HIP_MSG_SET_DEBUG_ALL 82
314 #define HIP_MSG_SET_DEBUG_MEDIUM 83
315+#define HIP_MSG_SET_DEBUG_LOW 81
316 #define HIP_MSG_SET_DEBUG_NONE 84
317 #define HIP_MSG_LOCATOR_GET 85
318 #define HIP_MSG_SET_LOCATOR_ON 89

Subscribers

People subscribed via source and target branches

to all changes: