[prev in list] [next in list] [prev in thread] [next in thread] 

List:       log4cxx-user
Subject:    Re: Configuring FileAppender target file path programmatically after
From:       "peter kwong" <laji () writeme ! com>
Date:       2009-05-25 18:08:59
Message-ID: 20090525180859.C63FE11581F () ws1-7 ! us4 ! outblaze ! com
[Download RAW message or body]

This is a multi-part message in MIME format.

--_----------=_1243274939147533
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset="iso-8859-1"

 Assaf,
  You don't really need RTTI compiled in because the dynamic casting is
not needed.
The getAppender() result can be assigned to a subclass of Appender
without casting.
Here is basically what I did (I editted the original code to just show
the essence. There may
be typos in this):

    // First set up file name string called 'fname'.
   snprintf(fname, MAX_LOG_FILENAME_LEN,"%s/mb%s.log",
                  logDir,
                  baseName);

    log4cxx::helpers::Pool p;  // buffer pool that for activateOptions()
to use
    FileAppenderPtr fa=loggerHandle_->getLoggerRepository()->
                           
getRootLogger()->getAppender("MyRollingAppenderSize");
    if (fa == 0)
    {
        // If there is no appender, then this is a serious error.
        // Logging will not work at all.
        return (-1);
    }

    // Configures the output log file name.
    fa->setFile(fname);
    fa->activateOptions(p);



BTW, when I used a rolling file appender and used configuration from both
an XML file and
programmatic definition of the log file name, I would get a file called
".1" created every time I ran the program.
I suspect it has something to do with the rolling file appender trying to
create a <file>.1 file, but since the XML
file did not have the file name, only ".1" got created. It was created as
soon as the program ran, and
not when the log file got too large and needed rolling over.

This problem was fixed by doing all the configuration programmatically
(or all via XML).

peter

  ----- Original Message -----
  From: log4cxx
  To: "Log4CXX User"
  Subject: Re: Configuring FileAppender target file path
  programmatically after Property Configuration
  Date: Wed, 20 May 2009 07:53:47 -0400


  Hi Assaf,

  We have been using this solution posted by Micha for a long time
  now. It works very well for us, in both Windows and various Unix
  systems.

  -Andy

  http://mail-archives.apache.org/mod_mbox/logging-log4cxx-user/200509.mbox/%3Cloom.20050915T064039-998@post.gmane.org%3E


  > Hi all,
  >
  > Is it possible to configure log4cxx using a property configurator
  > file, but then override the destination path of one of the
  > FileAppenders in code?

  > I ask because I have many instances of the same process running
  > and each has to log to a different (dynamically determined) file
  > location, but I still want to control the pattern, level, etc.
  > from one configuration file.
  >
  > Thanks

-- 
Be Yourself @ mail.com!
Choose From 200+ Email Addresses
Get a Free Account at www.mail.com


--_----------=_1243274939147533
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset="iso-8859-1"


<div>
Assaf,<br>&nbsp; You don't really need RTTI compiled in because the dynamic casting \
is not needed. <br>The getAppender() result can be assigned to a subclass of Appender \
without casting.<br>Here is basically what I did (I editted the original code to just \
show the essence. There may<br>be typos in this):<br><br>&nbsp;&nbsp;&nbsp; // First \
set up file name string called 'fname'.<br>&nbsp;&nbsp; snprintf(fname, \
MAX_LOG_FILENAME_LEN,"%s/mb%s.log", \
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
logDir,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
baseName);<br><br>&nbsp;&nbsp;&nbsp; log4cxx::helpers::Pool p;&nbsp; // buffer pool \
that for activateOptions() to use<br>&nbsp;&nbsp;&nbsp; FileAppenderPtr \
fa=loggerHandle_-&gt;getLoggerRepository()-&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp \
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
getRootLogger()-&gt;getAppender("MyRollingAppenderSize");<br>&nbsp;&nbsp;&nbsp; if \
(fa == 0)<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // If \
there is no appender, then this is a serious \
error.<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Logging will not work at \
all.<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return (-1);<br>&nbsp;&nbsp;&nbsp; \
}<br><br>&nbsp;&nbsp;&nbsp; // Configures the output log file \
name.<br>&nbsp;&nbsp;&nbsp; fa-&gt;setFile(fname);<br>&nbsp;&nbsp;&nbsp; \
fa-&gt;activateOptions(p);<br><br><br><br>BTW, when I used a rolling file appender \
and used configuration from both an XML file and<br>programmatic definition of the \
log file name, I would get a file called ".1" created every time I ran the \
program.<br>I suspect it has something to do with the rolling file appender trying to \
create a &lt;file&gt;.1 file, but since the XML<br>file did not have the file name, \
only ".1" got created. It was created as soon as the program ran, and <br>not when \
the log file got too large and needed rolling over.<br><br>This problem was fixed by \
doing all the configuration programmatically (or all via XML).<br><br> peter<br>
<blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; \
                padding-left: 5px;">----- Original Message -----<br>
From: log4cxx <log4cxx@gallandfamily.com><br>
To: "Log4CXX User" <log4cxx-user@logging.apache.org><br>
Subject: Re: Configuring FileAppender target file path programmatically after \
                Property Configuration<br>
Date: Wed, 20 May 2009 07:53:47 -0400<br>
<br>

<br>
Hi Assaf,<br>
<br>
We have been using this solution posted by Micha for a long time <br>
now. It works very well for us, in both Windows and various Unix <br>
systems.<br>
<br>
-Andy<br>
<br>
http://mail-archives.apache.org/mod_mbox/logging-log4cxx-user/200509.mbox/%3Cloom.20050915T064039-998@post.gmane.org%3E<br>
 <br>
&gt; Hi all,<br>
&gt;<br>
&gt; Is it possible to configure log4cxx using a property configurator <br>
&gt; file, but then override the destination path of one of the <br>
&gt; FileAppenders in code?<br>
<br>
&gt; I ask because I have many instances of the same process running <br>
&gt; and each has to log to a different (dynamically determined) file <br>
&gt; location, but I still want to control the pattern, level, etc. <br>
&gt; from one configuration file.<br>
&gt;<br>
&gt; Thanks<br>
</log4cxx-user@logging.apache.org></log4cxx@gallandfamily.com></blockquote>
</div>
<BR>

-- 
<div> Be Yourself @ mail.com!<br>
Choose From 200+ Email Addresses<br>
Get a <b>Free</b> Account at <a href="http://www.mail.com/Product.aspx" \
target="_blank">www.mail.com</a>!</div>

--_----------=_1243274939147533--


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic