On Thu, Mar 27, 2014 at 02:28:29PM +0000, Dave Tucker wrote:
> The Open vSwitch daemons written in C support user-configured logging
> patterns as described in ovs-appctl(8). This commit adds this capability
> to the daemons written in Python.
>
> - Add a '__log_patterns' attribute to the Vlog class
> - Populate this using the default patterns in ovs-appctl(8)
> - Add a '__start_time' attribute to the Vlog class to support '%r'
> - Update the '_log' method to build the log message according to the
> pattern
> - Add a 'set_pattern' method to allow the default patterns to be changed
> - Update 'set_levels_from_string' to support setting the pattern from a
> string
> - Remove milliseconds from date/time format as not available in strftime
>
> Signed-off-by: Dave Tucker <[email protected]>
Thanks for the patch!
It looks like this is your first Open vSwitch patch. It's customary to
include in a first patch an update to add yourself to AUTHORS.
I would add an item to NEWS to mention that this is now supported.
I see that the default log patterns in vlog.py differ slightly from the
default log patterns in vlog.h. Is that intentional (why?) or
accidental?
Here:
+ if "A" in m:
+ #ToDo: Not sure how we can get the application name
+ tmp = self._format_field(tmp, m, "")
in C we use argv[0] with the leading directory names stripped off, so I
think in Python you can start from sys.argv[0].
Here:
+ elif "P" in m:
+ #ToDo: Not sure how we can get the process ID
+ self._format_field(tmp, m, "")
I think you can use os.getpid()
I'd prefer to include support for milliseconds. It should be an easy
addition. See how we do it in the C version:
/* strftime() with an extension for high-resolution timestamps. Any '#'s in
* 'format' will be replaced by subseconds, e.g. use "%S.###" to obtain
results
* like "01.123". */
size_t
strftime_msec(char *s, size_t max, const char *format,
const struct tm_msec *tm)
{
size_t n;
n = strftime(s, max, format, &tm->tm);
if (n) {
char decimals[4];
char *p;
sprintf(decimals, "%03d", tm->msec);
for (p = strchr(s, '#'); p; p = strchr(p, '#')) {
char *d = decimals;
while (*p == '#') {
*p++ = *d ? *d++ : '0';
}
}
}
return n;
}
This commit should update lib/vlog.man so that -vPATTERN is now
documented for Python also.
Thanks,
Ben.
_______________________________________________
dev mailing list
[email protected]
http://openvswitch.org/mailman/listinfo/dev