How to find log file name?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

How to find log file name?

Dave Birdsall

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

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to find log file name?

Robert Middleton
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 <[hidden email]> 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


Loading...