The current log output format of the logger pkg is:
"[time] [service] [level]: 'msg'"
I would like to see an easier method to change the
output format instead of having to write a custom
logproc to change it. For example, I would like to see
the caller proc name also printed in the output message:
"[time] [service] [proc] [level]: 'msg'"
To support such a feature, the logger package should be
enhanced with a new API say logger::format which would
allow us to configure the logger output. Here's a
suggested syntax for logger::format API:
logger::format log ?<format>?
where <format> allows you to specify percent
substitutions; valid percent keys are %time, service,
%proc, %level, %callerstack and %message. The default
<format> could be {[%time] [%service] [%level]:
'%message'. If <format> is not specified, this command
would return the format value set previously. Setting
<format> to null {} will restore the default value.
logger::format time ?-format <dateformat>? ?-gmt boolean?
This cmd will allow the user to change the format of
%time substitution. The <dateformat> would allow
percent substitutions accepted by the [clock format
-format ..] command. For example, if the user just
wants to print 23:42:12 under %time, use the cmd
[logger::format time -format %H:%M:%S]. Again the
default value for the <dateformat> is same as for clock
format command. If -format option is specified without
any value, it will return the current value.
logger::format service ?<format>? where <format>
supports substitutions (%parent %tail) for namespace
qualifiers
logger::format proc ?<format>? where <format> supports
substitutions (%parent %tail) for namespace qualifiers
-----------------------Micahel's comments below--------
I like this proposal, and it isn't really that hard to
implement. Basically it calls for dynamic rewriting of
the custom logging command which is called by the
logger system with some more logic bits.
I thought of something similar, a bit more flexible
(but it got too complex then).
The interesting part is, if the logger::format command
should be a global option or a per service option. I
can imagine good reasons for a per service option (for
example think about tclhttpd, use one service for
logging access to the server, then another for server
errors and one for application code, each needs a
different format basicallly.).
Format inheritance would work as before.
Logged In: YES
user_id=69099
I was looking for something more limited, but a subset of
this. I find the width of the log's lines more than
necessary. I would like to be able to set the time format
to be "%D %T" instead of the current default clock format.
This can currently be done by using logproc to overwrite
existing logprocs, or by cheating and replacing stdoutcmd
and stderrcmd (which look to me like they should be
refactored, since they do the same thing except for the
channel).
Logged In: YES
user_id=69099
One other element that I forgot; right now the log file is
actually determined by the standard handles for stdout and
stderr. It would nice if the file handles for different
levels could be configured. Again, the logproc is sufficient
to override this, but that's something that must be customized.
The current definition of logproc does not say what
namespace the command to execute must exist in. While there
is a sample replacement proc, there is no example logproc
command to use it. So, would it be ${log}::logproc notice
::logtoserver
?