Hi, I wanted to switch out a logger instance for my own, so I implemented sys::Log and overrode the virtual log method. It all worked fine except that I couldn't receive any debug messages.
It seems a log level is only set from log.props if the Log is registered, meaning non-registered log instances can only ever be at info level.
Assuming this is an oversight, moving the log level setting out of the if statement seems to be the way forward.
diff -r dcdb455f1605 src/sys/java/fan/sys/Log.java
--- a/src/sys/java/fan/sys/Log.java Tue Jan 05 20:12:01 2016 -0500
+++ b/src/sys/java/fan/sys/Log.java Tue Jun 28 17:45:18 2016 +0100
@@ -75,12 +75,12 @@
// init and put into map
byName.put(name, self);
-
- // check for initial level
- String val = (String)Sys.sysPod.props(Uri.fromStr("log.props"), Duration.oneMin).get(name);
- if (val != null) self.level = LogLevel.fromStr(val);
}
}
+
+ // check for initial level
+ String val = (String)Sys.sysPod.props(Uri.fromStr("log.props"), Duration.oneMin).get(name);
+ if (val != null) self.level = LogLevel.fromStr(val);
}
//////////////////////////////////////////////////////////////////////////
This allows all log instances to have their log level set as per log.props.
Fandoc tweak
As an aside, it'd be helpful if Log.log() could have the following (or something similar) added to the docs as it's not currently clear.
This is method is only called from the convenience methods if logging is enabled for the given LogRec level.
brianMon 11 Jul 2016
Actually I'm not sure that is right. When you create unregistered logs they are assumed to be managed outside of the normal framework. So that is a fairly expensive hit to take especially for ephemeral logs which are getting created just once. They way we do logging in SkySpark for example uses a much more sophisticated system based on tagging and just setting log levels strictly by name would actually break stuff
SlimerDudeMon 11 Jul 2016
Sure, I can query log.props myself - and I've just noticed that Log, despite being const still lets you set Log.level. So that gets over my issue of not being able to create debug level logs.
SlimerDude Tue 28 Jun 2016
Hi, I wanted to switch out a logger instance for my own, so I implemented
sys::Log
and overrode the virtuallog
method. It all worked fine except that I couldn't receive anydebug
messages.It seems a log level is only set from
log.props
if theLog
is registered, meaning non-registered log instances can only ever be atinfo
level.Assuming this is an oversight, moving the log level setting out of the
if
statement seems to be the way forward.This allows all log instances to have their log level set as per
log.props
.Fandoc tweak
As an aside, it'd be helpful if Log.log() could have the following (or something similar) added to the docs as it's not currently clear.
brian Mon 11 Jul 2016
Actually I'm not sure that is right. When you create unregistered logs they are assumed to be managed outside of the normal framework. So that is a fairly expensive hit to take especially for ephemeral logs which are getting created just once. They way we do logging in SkySpark for example uses a much more sophisticated system based on tagging and just setting log levels strictly by name would actually break stuff
SlimerDude Mon 11 Jul 2016
Sure, I can query
log.props
myself - and I've just noticed thatLog
, despite beingconst
still lets you setLog.level
. So that gets over my issue of not being able to createdebug
level logs.