logging-log4cxx-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "log4cxx" <log4...@gallandfamily.com>
Subject Re: multi-user logger
Date Tue, 15 Jan 2008 22:11:10 GMT
Hi Christoph,

I'm copying and pasting an email I sent some time ago to someone else who was trying to do
something that log4cxx didn't quite handle. Perhaps modifying my suggestions below could get
you closer. For instance, you could add a user name to the environment, and then utilize that
in your configuration file:

--Start Copy--
I know it's not exactly what you are looking for, but perhaps you can adapt a method that
we use in our projects. We have many instances running of the same program, and for historical
purposes, always named log files with the Process ID in them to keep them separate. To do
this in log4cxx, before initializing, I add an environment variable:

#ifdef _MSC_VER
long processId = _getpid();
char logpid[20];
sprintf_s(logpid, "LOGPID=%ld", processId);
long processId = getpid();
char logpid[20];
sprintf(logpid, "LOGPID=%ld", processId);
#endif //_MSC_VER

Then in my configuration file I do:
  <appender name="RFA" class="org.apache.log4j.rolling.RollingFileAppender">
    <rollingPolicy class="org.apache.log4j.rolling.FixedWindowRollingPolicy">
      <param name="activeFileName" value="MyApp_${LOGPID}.log"/>
      <param name="fileNamePattern" value="MyApp_${LOGPID}.log.%i"/>
      <param name="minIndex" value="0"/>
      <param name="maxIndex" value="5"/>
    <triggeringPolicy class="org.apache.log4j.rolling.SizeBasedTriggeringPolicy">
      <param name="MaxFileSize" value="30MB"/>
    <layout class="org.apache.log4j.PatternLayout">
      <param name="ConversionPattern" value="%d{MM/dd HH:mm:ss.SSS} %c - %m%n"/>
    <param name="file" value="MyApp_${LOGPID}.log"/>
    <param name="append" value="false"/>

I'm not sure who handles it (log4cxx or the system), but somehow the variable gets properly
--End Copy--

I haven't tested it, but you might be able to use the variable in your logger configurations,
as well as in your appender configuration.

Hope this helps,

You wrote:

If the different settings are per module, then you could just configure
the logger for each module, and all user-specific sub-loggers would
inherit those properties.

If it's not that simple, maybe you could use the log4cxx API function
calls in your program to configure your loggers?  That would be more
flexible than the configuration file.

Or, perhaps you could configure a generic logger in the configuration
file, and then a portion of your program would attempt to duplicate that
logger's setting, modifying them as needed.

Just a thought.  If you found a way to solve your problem, let us know
how you did it, in case someone later wants to do something similar.

-David Steck
- Hide quoted text -

-----Original Message-----
From: Christoph Macheiner [mailto:Christoph.Macheiner@update.com]
Sent: Tuesday, December 04, 2007 4:42 PM
To: log4cxx-user@logging.apache.org
Subject: multi-user logger


i am currently trying to incorporate log4cxx into our multi-user
software. basically it is working well, but there is demand for more
extensive configuration (instead of our "fixed" configuration). the wish
is as follows: each user can work with different modules and/or
different logins, and all users/modules are serviced by one single
process (the single user/module per process scenario would of course be
no problem). assume, i want to use loggers named MODULE_NAME.USER_NAME
that should be configured dynamically from a single configuration file
(i use the domconfigurator).

the problem is, for example, with file appenders. there can be hundreds
of user/module combinations, but they can be grouped into a few
different loggers that need to be parametrized at runtime (like filename
should be MODULE_NAME.USER_NAME.log for one group, but only
MODULE_NAME.log for others etc).

the coolest thing would be to have the xml configuration file as a
"template" and create all loggers at runtime from that template xml.
then i could dynamically replace the filenames (etc) and/or reuse
already configured loggers for users of the same group. i cannot really
"hard-configure" all the loggers in the configuration file because, as i
mentioned, there could possibly be hundreds of different files.

so, is there a way to create all my loggers at runtime, from an xml
document provided on the fly? or is there an easier solution...

any help is greatly appreciated (and sorry for the long post). thanks
very much, christoph.

View raw message