syslog support to xentoollog
Guys
Is there any plans to add syslog support in to xentoollog.
Is this something that xentoollog would like to adopt .
Thanks
Gihan
Quoted 6 lines · Gihan Munasinghe
Guys
Is there any plans to add syslog support in to xentoollog.
Is this something that xentoollog would like to adopt .
That is something we definitely want, patches are welcome :-)
Quoted 4 lines · Stefano Stabellini
Quoted 2 lines · Gihan Munasinghe
Guys
Quoted 9 lines
Quoted 5 lines
Is there any plans to add syslog support in to xentoollog.
Is this something that xentoollog would like to adopt .
That is something we definitely want, patches are welcome :-)
Great I'll do some patching to get syslog working.
looking at the xentool.h, following definitions
#define XTL_STDIOSTREAM_SHOW_PID 01u
#define XTL_STDIOSTREAM_SHOW_DATE 02u
#define XTL_STDIOSTREAM_HIDE_PROGRESS 04u
I would suggest to be as
#define XTL_SHOW_PID 01u
#define XTL_SHOW_DATE 02u
#define XTL_HIDE_PROGRESS 04u
So it will be more generic for any loggers that will be implemented
also is everyone happy with following loglevel mappings between xentoollog_level and syslog
{XTL_DEBUG,LOG_DEBUG},
{XTL_VERBOSE,LOG_DEBUG},
{XTL_DETAIL,LOG_DEBUG},
{XTL_PROGRESS,LOG_DEBUG},
{XTL_INFO,LOG_INFO},
{XTL_NOTICE,LOG_NOTICE},
{XTL_WARN,LOG_WARNING},
{XTL_ERROR,LOG_ERR},
{XTL_CRITICAL,LOG_CRIT}Thanks
Gihan
Gihan Munasinghe writes ("Re: [Xen-devel] syslog support to xentoollog"):
Quoted 1 line
Great I'll do some patching to get syslog working.
Excellent.
Quoted 11 lines
looking at the
xentool.h, following definitions#define
XTL_STDIOSTREAM_SHOW_PID01u
#defineXTL_STDIOSTREAM_SHOW_DATE02u
#defineXTL_STDIOSTREAM_HIDE_PROGRESS04uI would suggest to be as
#defineXTL_SHOW_PID01u
#defineXTL_SHOW_DATE02u
#defineXTL_HIDE_PROGRESS04u
So it will be more generic for any loggers that will be implemented
Sure.
Note though that XTL_SHOW_DATE isn't going to be relevant for syslog since in syslog the date is put in by syslogd.
Quoted 12 lines
also is everyone happy with following loglevel mappings between
xentoollog_leveland syslog{XTL_DEBUG,LOG_DEBUG}, {XTL_VERBOSE,LOG_DEBUG}, {XTL_DETAIL,LOG_DEBUG}, {XTL_PROGRESS,LOG_DEBUG}, {XTL_INFO,LOG_INFO}, {XTL_NOTICE,LOG_NOTICE}, {XTL_WARN,LOG_WARNING}, {XTL_ERROR,LOG_ERR}, {XTL_CRITICAL,LOG_CRIT}
That's probably right.
Ian.
PATCH 1/1 syslog support to xentoollog
Guys
See the attach patch, this implements a xentoollog consumer that can log in to syslog
Following are the changes
xentoollog.h:
1) Generic, xtl_logger_set_minlevel and xtl_logger_adjust_flags functions to be called from outside,
2) Making logger flags to be more generic
3) Change the struct xentool_logger, each logger will implement its own "set_minlevel" and "adjust_flags" which will be invoked by xtl_logger_set_minlevel and xtl_logger_adjust_flags generic functions.
4) New function prototype to create a xentool_logger_syslogger
Going forward I would like to suggest that xentoollog.h file should only have generic functions, except for xtl_createlogger_* functions. Logger type specific function should not be included(e.g xtl_stdiostream_set_minlevel ) this will make sure outside code can switch from one logger to another (from stdiologger to syslogger vice versa) with out breaking the code.
xtl_core.c:
1) Implementation of xtl_logger_set_minlevel and xtl_logger_adjust_flags functions.
xtl_logger_syslog.c :
New logger implementation to log in to syslog.
I did some testing by changing the code in xl. This seems to work, but I would really like if more people can test this. Also could someone look @ the syslogger_progress function and add any extra bits if needed, I did a very basic implementation of this.
Thanks
Gihan
tools/libxc/Makefile +1 -0
@@ -29,6 +29,7 @@ CTRL_SRCS-y += xc_memshr.c CTRL_SRCS-y += xtl_core.c CTRL_SRCS-y += xtl_logger_stdio.c +CTRL_SRCS-y += xtl_logger_syslog.c CTRL_SRCS-$(CONFIG_X86) += xc_pagetab.c CTRL_SRCS-$(CONFIG_Linux) += xc_linux.c CTRL_SRCS-$(CONFIG_SunOS) += xc_solaris.c
tools/libxc/xentoollog.h +46 -0
83 lines not on this page · raw message
tools/libxc/xtl_core.c +17 -1
@@ -63,7 +63,23 @@ logger->progress (logger, context, doing_what, percent, done, total); } +void xtl_logger_set_minlevel (struct xentoollog_logger *logger, +xentoollog_level min_level){ +if (!logger || !logger->set_minlevel)return ; + + logger->set_minlevel (logger,min_level); +} + +void xtl_logger_adjust_flags (struct xentoollog_logger *logger, +unsigned set_flags,unsigned clear_flags){ +if (!logger || !logger->adjust_flags)return ; + + logger->adjust_flags (logger,set_flags,clear_flags); +} + +void xtl_logger_destroy (struct xentoollog_logger *logger) { -if (!logger)return ; +if (!logger || !logger->destroy)return ; + logger->destroy (logger); }
tools/libxc/xtl_logger_stdio.c +14 -0
@@ -124,6 +124,20 @@ lg->flags = new_flags; } +static void stdiostream_set_minlevel (struct xentoollog_logger *logger_in, +xentoollog_level min_level){ + +xentoollog_logger_stdiostream *lg = (void *)logger_in; +xtl_stdiostream_set_minlevel (lg,min_level); +} + +static void stdiostream_adjust_flags (struct xentoollog_logger *logger_in, +unsigned set_flags,unsigned clear_flags) { + +xentoollog_logger_stdiostream *lg = (void *)logger_in; +xtl_stdiostream_adjust_flags (lg,set_flags,clear_flags); +} +xentoollog_logger_stdiostream *xtl_createlogger_stdiostream (FILE *f,xentoollog_level min_level,unsigned flags) {xentoollog_logger_stdiostream newlogger;
tools/libxc/xtl_logger_syslog.c +152 -0
152 lines not on this page · raw message
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Quoted 4 lines · Gihan Munasinghe
Guys
See the attach patch, this implements a xentoollog consumer that can log in to syslog
I'll wait for Ian to review this one before applying it.
-- Keir
Quoted 36 lines
Following are the changes
xentoollog.h:
1) Generic,xtl_logger_set_minlevelandxtl_logger_adjust_flagsfunctions to be called from outside,
2) Making logger flags to be more generic
3) Change the structxentool_logger, each logger will implement its own "set_minlevel" and "adjust_flags" which will be invoked byxtl_logger_set_minlevelandxtl_logger_adjust_flagsgeneric functions.
4) New function prototype to create axentool_logger_sysloggerGoing forward I would like to suggest that
xentoollog.hfile should only have generic functions, except for xtl_createlogger_* functions. Logger type specific function should not beincluded(e.g xtl_stdiostream_set_minlevel )this will make sure outside code can switch from one logger to another (from stdiologger to syslogger vice versa) with out breaking the code.
xtl_core.c:
1) Implementation ofxtl_logger_set_minlevelandxtl_logger_adjust_flagsfunctions.
xtl_logger_syslog.c:
New logger implementation to log in to syslog.I did some testing by changing the code in xl. This seems to work, but I would really like if more people can test this.
Also could someone look @ thesyslogger_progressfunction and add any extra bits if needed, I did a very basic implementation of this.Signed-off-by Gihan Munasinghe <[email protected]>Thanks
Gihan
Keir Fraser writes ("Re: [Xen-devel] [PATCH] syslog support to xentoollog"):
Quoted 1 line
I'll wait for Ian to review this one before applying it.
Great, thanks. I think there are a few things that need doing.
Ian.
Gihan Munasinghe writes ("[PATCH] syslog support to xentoollog"):
Quoted 6 lines
Going forward I would like to suggest that
xentoollog.hfile should only have generic functions, except for xtl_createlogger_* functions. Logger type specific function should not beincluded(e.g xtl_stdiostream_set_minlevel )this will make sure outside code can switch from one logger to another (from stdiologger to syslogger vice versa) with out breaking the code.
In general this is a good idea but it's not sensible to make it a hard and fast rule. Eg, if you had a function xtl_syslog_change_facility() it wouldn't make any sense for it to be implemented by stdiostream.
Ian.
Quoted 10 lines · Ian Jackson
Gihan Munasinghe writes ("[PATCH] syslog support to xentoollog"):
Quoted 2 lines
Going forward I would like to suggest that
xentoollog.hfile should only have generic functions, except for xtl_createlogger_* functions. Logger type specific function should not beincluded(e.g xtl_stdiostream_set_minlevel )this will make sure outside code can switch from one logger to another (from stdiologger to syslogger vice versa) with out breaking the code.In general this is a good idea but it's not sensible to make it a hard and fast rule. Eg, if you had a function
xtl_syslog_change_facility()it wouldn't make any sense for it to be implemented by stdiostream.
Should a call like xtl_syslog_change_facility() given out directly to the library users. this call can be wrapped with in a more generic call like xtl_cahnge_log_place(struct xentool_logger , void *new_place);
In stdiostream implementation this can be caste to a stream and in syslogger implementation this can be cast as a facility. If some logger doesn't want to implement that we can have empty implementation
Well may be it should not be a hard and fast rule, but more of a best practice scenario then.
Thanks
Gihan
Gihan Munasinghe writes ("Re: [PATCH] syslog support to xentoollog"):
Quoted 4 lines
Should a call like
xtl_syslog_change_facility()given out directly to the library users. this call can be wrapped with in a more generic call likextl_cahnge_log_place(struct xentool_logger , void *new_place);
This is a bad idea because the type and semantics of new_place are not defined.
Quoted 2 lines
In stdiostream implementation this can be caste to a stream and in syslogger implementation this can be cast as a facility.
Yuck.
Ian.
Gihan Munasinghe writes ("[PATCH] syslog support to xentoollog"):
Quoted 2 lines
Also could someone look @ the
syslogger_progressfunction and add any extra bits if needed, I did a very basic implementation of this.
I think it should at the very least limit the messages until the percentage changes by at least (say) 5%. The progress function may be called very very often.
Ian.
Quoted 10 lines · Ian Jackson
Gihan Munasinghe writes ("[PATCH] syslog support to xentoollog"):
Quoted 2 lines
Also could someone look @ the
syslogger_progressfunction and add any extra bits if needed, I did a very basic implementation of this.I think it should at the very least limit the messages until the percentage changes by at least (say) 5%. The progress function may be called very very often.
Is this the only change that need to happen, are you happy with the rest of the patch.
Tanks
Gihan
Gihan Munasinghe writes ("[PATCH] syslog support to xentoollog"):
Quoted 2 lines
See the attach patch, this implements a xentoollog consumer that can log in to syslog
Thanks. Here are my comments after reading the code in detail:
None of your code seems to implement min_level. At the very least you should be able to suppress logging of progress messages to syslog.
Quoted 1 line
+//-- Should be depricated not generic enough --//
Could you please to use the same comment style as the rest of this file ? Switching styles in a single file makes the it particularly hard to read.
tools/libxc/xentoollog.h line 92
Quoted 4 lines
tools/libxc/xentoollog.h +4
-0+/** +Create a logger that will log to syslog +syslog_facility is the facilities that are in the sys/syslog.h +edit /etc/syslog.conf file to indicate where you wansyslog to send log data
Block comments should be
/*
* Like this
*/
so that they can be easily distinguished from code.
Quoted 3 lines
+//This method need to be depricated use more generic
xtl_logger_set_minlevelmethod insted
void xtl_stdiostream_set_minlevel(xentoollog_logger_stdiostream*,xentoollog_level min_level);
If we are going to make these methods of every logger, you can just delete these two functions. This logging stuff is new enough that we don't care about backward API compatibility. Also "deprecated" is spelt thus.
tools/libxc/xtl_core.c line 68
Quoted 3 lines
tools/libxc/xtl_core.c +3
-0+void xtl_logger_set_minlevel (struct xentoollog_logger *logger, +xentoollog_level min_level){ +if (!logger || !logger->set_minlevel)return ;
I think the test for !logger is wrong: I think if you call this function and pass it logger=NULL you should get a crash. But it's fine to skip the call for loggers that don't support it (ie have 0 in the vtable).
tools/libxc/xtl_core.c line 82
Quoted 3 lines
void
xtl_logger_destroy(struct xentoollog_logger *logger){tools/libxc/xtl_core.c +1
-1-if (!logger)return ; +if (!logger || !logger->destroy)return ;
This is wrong because every logger must definitely have a ->destroy method, since it at least has to free up the logger structure. Any which didn't must either be broken, or be some kind of static logger which should never be destroyed.
tools/libxc/xtl_logger_syslog.c line 22
Quoted 4 lines
tools/libxc/xtl_logger_syslog.c +4
-0+typedef struct _log_map { +xentoollog_level xen_log; +int syslog_level; +}LOG_MAP ;
Do not use identifiers which start with "_"; they are reserved for the C implementation. (In this case it's OK I think but it's a very bad habit.) There seems to be no need for this struct to have a struct tag as well as a typedef.
Also, as a matter of style, I think the use of all caps for type names is a bad idea. Capslock is normally used for macros.
tools/libxc/xtl_logger_syslog.c line 25
Quoted 2 lines
tools/libxc/xtl_logger_syslog.c +2
-0+LOG_MAP log_mappings[] = + {
You forgot "static const".
Quoted 1 line
+int
maptable_len= sizeof(log_mappings)/sizeof(LOG_MAP);
This should be a #define, surely. If not, you forgot "static const". But it's only used in one place. Perhaps you should put it there.
Quoted 1 line
+ buffer = (char *)calloc(1024,sizeof(char));
sizeof(char) is 1 by definition.
You should not cast the result from calloc.
Quoted 1 line
+ if (context && (
lg->flags& XTL_SHOW_PID)){
syslog already knows how to add the pid to messages.
Quoted 1 line
+
sprintf(new_format,"[%s] : ",context);
...
Quoted 1 line
+
sprintf(new_format,"[%s] : ",strerror(errnoval));
This formatting is different to that produced by stdiostream. Surely the messages should try to be as similar as possible.
tools/libxc/xtl_logger_syslog.c line 81
Quoted 3 lines
tools/libxc/xtl_logger_syslog.c +3
-0+char *new_format = (char *)calloc (7 +strlen (context),sizeof (char )); +sprintf (new_format,"[%s] : " ,context); +strcat (buffer,new_format);
Use asprintf. In fact you could profitably replace much of the meat of this function with a single asprintf call.
Quoted 1 line
+
strcat(buffer,format);
This is wrong. What if the context or the errno value contain "%s" or something ? You can prepend a single "%s" to the format if you want to prepend a fixed string.
tools/libxc/xtl_logger_syslog.c line 117
Quoted 3 lines
tools/libxc/xtl_logger_syslog.c +3
-0+syslog (get_syslog_level (XTL_PROGRESS ),"%s%s" "%s: %lu/%lu %3d%%" , + context?context:"" , context?": " :"" , + doing_what, done, total, percent);
You should arrange that the syslog level lookup - a linear search - is not done on every call to ->progress, which may be called very very requently.
Ian.