Jason
Jason

Reputation: 12283

Using logback, how do I add a platform dependent log file appender?

I'm using logback and the log location will vary depending on the platform (see my other related question: What's the best practice for log file locations in Java desktop applications?).

How do I tell logback to use the log file determined from the platform? I cannot hard code the log file in logback.xml because it will be a different file for each platform.

I do need the settings from logback.xml to be used for the file appender, though.

I have a console appender in logback.xml. Perhaps for this additional requirement the settings can be transfered to the file appender?

So to be clear, this is a two part question:

  1. How do I add a file appender with a location based on the platform.
  2. How do I have this file appender keep the settings defined in logback.xml.

Upvotes: 2

Views: 150

Answers (1)

Peter Lawrey
Peter Lawrey

Reputation: 533500

You are going to have to put in configuration somewhere. The simplest is to have a logback.xml for each platform, but you could have another configuration file or use a command line property (which means a different startup for each platform)

Upvotes: 1

Related Questions