You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4cxx-user@logging.apache.org by Dave Birdsall <da...@esgyn.com> on 2016/08/22 22:48:39 UTC
How to find log file name?
Hi,
I’m a newbie to log4cxx (and lack familiarity with log4j).
I have what is likely a naïve question.
Suppose I am about to log some information to a log file. I’d like to tell
my user where that log file is (the path and file name) so the user doesn’t
have to hunt for it. Is there a programmatic way to obtain the log file
name?
Thanks,
Dave
Re: How to find log file name?
Posted by Thorsten Schöning <ts...@am-soft.de>.
Guten Tag Dave Birdsall,
am Dienstag, 23. August 2016 um 00:48 schrieben Sie:
> Suppose I am about to log some information to a log file. I’d like
> to tell my user where that log file is (the path and file name) so
> the user doesn’t have to hunt for it. Is there a programmatic way to obtain the log file name?
This is the wrong approach. Ask yourself who implements log4cxx with
which behaviour into your application. Most likely it's you, else you
wouldn't be able to programmatically ask for the log file name/path.
So why do you implement it in a way that makes you need to ask for
such a log file name/path at all?
You don't want that, instead you want to provide the ability that you
or your user can simply configure those paths, so you don't need to
query anything. Read the following document, especially the
"Configuration" section. The format used is pretty much the same like
that of log4j, so you can use their documentation as well.
https://logging.apache.org/log4cxx/latest_stable/usage.html
https://wiki.apache.org/logging-log4j/Log4jXmlFormat
Mit freundlichen Grüßen,
Thorsten Schöning
--
Thorsten Schöning E-Mail: Thorsten.Schoening@AM-SoFT.de
AM-SoFT IT-Systeme http://www.AM-SoFT.de/
Telefon...........05151- 9468- 55
Fax...............05151- 9468- 88
Mobil..............0178-8 9468- 04
AM-SoFT GmbH IT-Systeme, Brandenburger Str. 7c, 31789 Hameln
AG Hannover HRB 207 694 - Geschäftsführer: Andreas Muchow
Re: How to find log file name?
Posted by Robert Middleton <os...@gmail.com>.
Dave,
Depending on your specific use case, it may be easier to simply log to a
well-known location on the system and point the user to that location. At
least one problem with trying to figure out the location programatically is
that a single logger can log to multiple sources at once, e.g. multiple
files or to a database.
Regardless, you can probably use the following sequence(note: I have not
tried this myself)
1. Get the logger that you want to get the appender for(that is, you
must have a logger that logs to the file you want to get the name of)
2. Use logger.getAppender( std::string name ) or logger.getAppenders()
and loop through all of the appenders.
3. Figure out which of the appenders is a FileAppender:
https://logging.apache.org/log4cxx/latest_stable/apidocs/classlog4cxx_1_1_file_appender.html
(I think you need to use dynamic_cast here, but I'm not positive, I don't
do much casting in C++)
4. Call the FileAppender.getFile() method.
-Robert Middleton
On Mon, Aug 22, 2016 at 6:48 PM, Dave Birdsall <da...@esgyn.com>
wrote:
> Hi,
>
>
>
> I’m a newbie to log4cxx (and lack familiarity with log4j).
>
>
>
> I have what is likely a naïve question.
>
>
>
> Suppose I am about to log some information to a log file. I’d like to tell
> my user where that log file is (the path and file name) so the user doesn’t
> have to hunt for it. Is there a programmatic way to obtain the log file
> name?
>
>
>
> Thanks,
>
>
>
> Dave
>