Log4j programmatic configure to ONLY save in file
I would like to have a piece of code that would ONLY save ALL(Or just the ERROR logs) from the log4j to a file. All the solutions that I found and tried are still showing information in the console, which I don't want to.
I tried this piece of code:
public static void configureLogging(String fileName) {
ConfigurationBuilder<BuiltConfiguration> builder = ConfigurationBuilderFactory.newConfigurationBuilder();
builder.setStatusLevel(Level.ALL);
LayoutComponentBuilder layoutBuilder = builder.newLayout("PatternLayout").addAttribute("pattern", "%d [%t] %-5level: %msg%n%throwable");
ComponentBuilder triggeringPolicies = builder.newComponent("Policies")
.addComponent(builder.newComponent("CronTriggeringPolicy")
.addAttribute("schedule", "0 0 0 * * ?"))
.addComponent(builder.newComponent("SizeBasedTriggeringPolicy")
.addAttribute("size", "100M"));
AppenderComponentBuilder rollingFile
= builder.newAppender("rolling", "RollingFile").add(layoutBuilder);
rollingFile.addAttribute("fileName", fileName + ".log");
rollingFile.addAttribute("filePattern", fileName + "-%d{MM-dd-yy}.log.gz");
rollingFile.addComponent(triggeringPolicies);
builder.add(rollingFile);
builder.add(builder.newRootLogger(Level.ALL).add(builder.newAppenderRef("rolling")));
builder.setConfigurationName("BuilderTest");
Configurator.initialize(builder.build());
}
but I'm seeing everything in the console terminal:
2018-11-16 11:24:42,884 main DEBUG Apache Log4j Core 2.11.1 initializing configuration org.apache.logging.log4j.core.config.builder.impl.BuiltConfiguration@3b0143d3
2018-11-16 11:24:42,887 main DEBUG Installed 1 script engine
2018-11-16 11:24:43,166 main DEBUG Oracle Nashorn version: 1.8.0_144, language: ECMAScript, threading: Not Thread Safe, compile: true, names: [nashorn, Nashorn, js, JS, JavaScript, javascript, ECMAScript, ecmascript], factory class: jdk.nashorn.api.scripting.NashornScriptEngineFactory
2018-11-16 11:24:43,166 main DEBUG PluginManager 'Core' found 117 plugins
2018-11-16 11:24:43,166 main DEBUG PluginManager 'Level' found 0 plugins
2018-11-16 11:24:43,168 main DEBUG PluginManager 'Lookup' found 13 plugins
2018-11-16 11:24:43,168 main DEBUG Building Plugin[name=AppenderRef, class=org.apache.logging.log4j.core.config.AppenderRef].
2018-11-16 11:24:43,170 main DEBUG createAppenderRef(ref="rolling", level="null", Filter=null)
2018-11-16 11:24:43,170 main DEBUG Building Plugin[name=root, class=org.apache.logging.log4j.core.config.LoggerConfig$RootLogger].
2018-11-16 11:24:43,173 main DEBUG createLogger(additivity="null", level="ALL", includeLocation="null", ={rolling}, ={}, Configuration(BuilderTest), Filter=null)
2018-11-16 11:24:43,174 main DEBUG Building Plugin[name=loggers, class=org.apache.logging.log4j.core.config.LoggersPlugin].
Could anyone explain what is wrong with my approach?
Many Thanks,
Joao
java log4j2
add a comment |
I would like to have a piece of code that would ONLY save ALL(Or just the ERROR logs) from the log4j to a file. All the solutions that I found and tried are still showing information in the console, which I don't want to.
I tried this piece of code:
public static void configureLogging(String fileName) {
ConfigurationBuilder<BuiltConfiguration> builder = ConfigurationBuilderFactory.newConfigurationBuilder();
builder.setStatusLevel(Level.ALL);
LayoutComponentBuilder layoutBuilder = builder.newLayout("PatternLayout").addAttribute("pattern", "%d [%t] %-5level: %msg%n%throwable");
ComponentBuilder triggeringPolicies = builder.newComponent("Policies")
.addComponent(builder.newComponent("CronTriggeringPolicy")
.addAttribute("schedule", "0 0 0 * * ?"))
.addComponent(builder.newComponent("SizeBasedTriggeringPolicy")
.addAttribute("size", "100M"));
AppenderComponentBuilder rollingFile
= builder.newAppender("rolling", "RollingFile").add(layoutBuilder);
rollingFile.addAttribute("fileName", fileName + ".log");
rollingFile.addAttribute("filePattern", fileName + "-%d{MM-dd-yy}.log.gz");
rollingFile.addComponent(triggeringPolicies);
builder.add(rollingFile);
builder.add(builder.newRootLogger(Level.ALL).add(builder.newAppenderRef("rolling")));
builder.setConfigurationName("BuilderTest");
Configurator.initialize(builder.build());
}
but I'm seeing everything in the console terminal:
2018-11-16 11:24:42,884 main DEBUG Apache Log4j Core 2.11.1 initializing configuration org.apache.logging.log4j.core.config.builder.impl.BuiltConfiguration@3b0143d3
2018-11-16 11:24:42,887 main DEBUG Installed 1 script engine
2018-11-16 11:24:43,166 main DEBUG Oracle Nashorn version: 1.8.0_144, language: ECMAScript, threading: Not Thread Safe, compile: true, names: [nashorn, Nashorn, js, JS, JavaScript, javascript, ECMAScript, ecmascript], factory class: jdk.nashorn.api.scripting.NashornScriptEngineFactory
2018-11-16 11:24:43,166 main DEBUG PluginManager 'Core' found 117 plugins
2018-11-16 11:24:43,166 main DEBUG PluginManager 'Level' found 0 plugins
2018-11-16 11:24:43,168 main DEBUG PluginManager 'Lookup' found 13 plugins
2018-11-16 11:24:43,168 main DEBUG Building Plugin[name=AppenderRef, class=org.apache.logging.log4j.core.config.AppenderRef].
2018-11-16 11:24:43,170 main DEBUG createAppenderRef(ref="rolling", level="null", Filter=null)
2018-11-16 11:24:43,170 main DEBUG Building Plugin[name=root, class=org.apache.logging.log4j.core.config.LoggerConfig$RootLogger].
2018-11-16 11:24:43,173 main DEBUG createLogger(additivity="null", level="ALL", includeLocation="null", ={rolling}, ={}, Configuration(BuilderTest), Filter=null)
2018-11-16 11:24:43,174 main DEBUG Building Plugin[name=loggers, class=org.apache.logging.log4j.core.config.LoggersPlugin].
Could anyone explain what is wrong with my approach?
Many Thanks,
Joao
java log4j2
Could you please explain why do you need to do programmatic configuration? Generally this should be avoided unless absolutely necessary because it makes your code depend on the log4j2 implementation details rather than on the public API.
– D.B.
Nov 17 '18 at 6:57
add a comment |
I would like to have a piece of code that would ONLY save ALL(Or just the ERROR logs) from the log4j to a file. All the solutions that I found and tried are still showing information in the console, which I don't want to.
I tried this piece of code:
public static void configureLogging(String fileName) {
ConfigurationBuilder<BuiltConfiguration> builder = ConfigurationBuilderFactory.newConfigurationBuilder();
builder.setStatusLevel(Level.ALL);
LayoutComponentBuilder layoutBuilder = builder.newLayout("PatternLayout").addAttribute("pattern", "%d [%t] %-5level: %msg%n%throwable");
ComponentBuilder triggeringPolicies = builder.newComponent("Policies")
.addComponent(builder.newComponent("CronTriggeringPolicy")
.addAttribute("schedule", "0 0 0 * * ?"))
.addComponent(builder.newComponent("SizeBasedTriggeringPolicy")
.addAttribute("size", "100M"));
AppenderComponentBuilder rollingFile
= builder.newAppender("rolling", "RollingFile").add(layoutBuilder);
rollingFile.addAttribute("fileName", fileName + ".log");
rollingFile.addAttribute("filePattern", fileName + "-%d{MM-dd-yy}.log.gz");
rollingFile.addComponent(triggeringPolicies);
builder.add(rollingFile);
builder.add(builder.newRootLogger(Level.ALL).add(builder.newAppenderRef("rolling")));
builder.setConfigurationName("BuilderTest");
Configurator.initialize(builder.build());
}
but I'm seeing everything in the console terminal:
2018-11-16 11:24:42,884 main DEBUG Apache Log4j Core 2.11.1 initializing configuration org.apache.logging.log4j.core.config.builder.impl.BuiltConfiguration@3b0143d3
2018-11-16 11:24:42,887 main DEBUG Installed 1 script engine
2018-11-16 11:24:43,166 main DEBUG Oracle Nashorn version: 1.8.0_144, language: ECMAScript, threading: Not Thread Safe, compile: true, names: [nashorn, Nashorn, js, JS, JavaScript, javascript, ECMAScript, ecmascript], factory class: jdk.nashorn.api.scripting.NashornScriptEngineFactory
2018-11-16 11:24:43,166 main DEBUG PluginManager 'Core' found 117 plugins
2018-11-16 11:24:43,166 main DEBUG PluginManager 'Level' found 0 plugins
2018-11-16 11:24:43,168 main DEBUG PluginManager 'Lookup' found 13 plugins
2018-11-16 11:24:43,168 main DEBUG Building Plugin[name=AppenderRef, class=org.apache.logging.log4j.core.config.AppenderRef].
2018-11-16 11:24:43,170 main DEBUG createAppenderRef(ref="rolling", level="null", Filter=null)
2018-11-16 11:24:43,170 main DEBUG Building Plugin[name=root, class=org.apache.logging.log4j.core.config.LoggerConfig$RootLogger].
2018-11-16 11:24:43,173 main DEBUG createLogger(additivity="null", level="ALL", includeLocation="null", ={rolling}, ={}, Configuration(BuilderTest), Filter=null)
2018-11-16 11:24:43,174 main DEBUG Building Plugin[name=loggers, class=org.apache.logging.log4j.core.config.LoggersPlugin].
Could anyone explain what is wrong with my approach?
Many Thanks,
Joao
java log4j2
I would like to have a piece of code that would ONLY save ALL(Or just the ERROR logs) from the log4j to a file. All the solutions that I found and tried are still showing information in the console, which I don't want to.
I tried this piece of code:
public static void configureLogging(String fileName) {
ConfigurationBuilder<BuiltConfiguration> builder = ConfigurationBuilderFactory.newConfigurationBuilder();
builder.setStatusLevel(Level.ALL);
LayoutComponentBuilder layoutBuilder = builder.newLayout("PatternLayout").addAttribute("pattern", "%d [%t] %-5level: %msg%n%throwable");
ComponentBuilder triggeringPolicies = builder.newComponent("Policies")
.addComponent(builder.newComponent("CronTriggeringPolicy")
.addAttribute("schedule", "0 0 0 * * ?"))
.addComponent(builder.newComponent("SizeBasedTriggeringPolicy")
.addAttribute("size", "100M"));
AppenderComponentBuilder rollingFile
= builder.newAppender("rolling", "RollingFile").add(layoutBuilder);
rollingFile.addAttribute("fileName", fileName + ".log");
rollingFile.addAttribute("filePattern", fileName + "-%d{MM-dd-yy}.log.gz");
rollingFile.addComponent(triggeringPolicies);
builder.add(rollingFile);
builder.add(builder.newRootLogger(Level.ALL).add(builder.newAppenderRef("rolling")));
builder.setConfigurationName("BuilderTest");
Configurator.initialize(builder.build());
}
but I'm seeing everything in the console terminal:
2018-11-16 11:24:42,884 main DEBUG Apache Log4j Core 2.11.1 initializing configuration org.apache.logging.log4j.core.config.builder.impl.BuiltConfiguration@3b0143d3
2018-11-16 11:24:42,887 main DEBUG Installed 1 script engine
2018-11-16 11:24:43,166 main DEBUG Oracle Nashorn version: 1.8.0_144, language: ECMAScript, threading: Not Thread Safe, compile: true, names: [nashorn, Nashorn, js, JS, JavaScript, javascript, ECMAScript, ecmascript], factory class: jdk.nashorn.api.scripting.NashornScriptEngineFactory
2018-11-16 11:24:43,166 main DEBUG PluginManager 'Core' found 117 plugins
2018-11-16 11:24:43,166 main DEBUG PluginManager 'Level' found 0 plugins
2018-11-16 11:24:43,168 main DEBUG PluginManager 'Lookup' found 13 plugins
2018-11-16 11:24:43,168 main DEBUG Building Plugin[name=AppenderRef, class=org.apache.logging.log4j.core.config.AppenderRef].
2018-11-16 11:24:43,170 main DEBUG createAppenderRef(ref="rolling", level="null", Filter=null)
2018-11-16 11:24:43,170 main DEBUG Building Plugin[name=root, class=org.apache.logging.log4j.core.config.LoggerConfig$RootLogger].
2018-11-16 11:24:43,173 main DEBUG createLogger(additivity="null", level="ALL", includeLocation="null", ={rolling}, ={}, Configuration(BuilderTest), Filter=null)
2018-11-16 11:24:43,174 main DEBUG Building Plugin[name=loggers, class=org.apache.logging.log4j.core.config.LoggersPlugin].
Could anyone explain what is wrong with my approach?
Many Thanks,
Joao
java log4j2
java log4j2
asked Nov 16 '18 at 11:28
joao.sauerjoao.sauer
12411
12411
Could you please explain why do you need to do programmatic configuration? Generally this should be avoided unless absolutely necessary because it makes your code depend on the log4j2 implementation details rather than on the public API.
– D.B.
Nov 17 '18 at 6:57
add a comment |
Could you please explain why do you need to do programmatic configuration? Generally this should be avoided unless absolutely necessary because it makes your code depend on the log4j2 implementation details rather than on the public API.
– D.B.
Nov 17 '18 at 6:57
Could you please explain why do you need to do programmatic configuration? Generally this should be avoided unless absolutely necessary because it makes your code depend on the log4j2 implementation details rather than on the public API.
– D.B.
Nov 17 '18 at 6:57
Could you please explain why do you need to do programmatic configuration? Generally this should be avoided unless absolutely necessary because it makes your code depend on the log4j2 implementation details rather than on the public API.
– D.B.
Nov 17 '18 at 6:57
add a comment |
1 Answer
1
active
oldest
votes
Without more details it's hard to give an exact answer, however, I will try to help point you in the right direction.
First, I would highly recommend that you do not use programmatic configuration unless you have a very good reason to do so. Log4j2 provides some very nice features that make it possible to do almost everything via a configuration file.
My best guess is that you want to use a dynamic file name that is somehow selected at runtime. If this is the case you can definitely do this using log4j2 lookups. In another answer I wrote an example that uses the system properties lookup. As you can see the file name is dynamic based on a system property rather than being static or hardcoded into the config file. There are many other lookups, so I suggest reading the manual carefully and choosing one that best fits your needs.
As for your question of how to send all logs to a file it's as simple as not specifying a console appender. As stated in the log4j2 manual:
Appenders are responsible for delivering LogEvents to their
destination.
Referring again to the other answer I wrote you'll also notice that the configuration does not use console appender and thus does not generate any console messages.
Since I do not see you creating a console appender I'm betting that the issue is the following: builder.setStatusLevel(Level.ALL);
This would appear to be setting the log4j2 status logger to a level of "ALL" meaning it's going to generate all of the internal log4j2 log messages. I would recommend using a level of "WARN" or "ERROR" but if you really want to make sure that messages are never sent to console you could set this to "OFF".
hi. I just don't want to have to pass my .jar file with the log4j2.xml file. Does make sense or I'm missing something here?
– joao.sauer
Nov 22 '18 at 9:35
I would say logging configuration is always the choice of the user of an application. You could provide a default configuration but ultimately whoever uses the jar should configure logging. Your responsibility is to inform the user how they can configure it. E.g. by telling them your code uses log4j2
– D.B.
Nov 22 '18 at 16:24
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53336964%2flog4j-programmatic-configure-to-only-save-in-file%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Without more details it's hard to give an exact answer, however, I will try to help point you in the right direction.
First, I would highly recommend that you do not use programmatic configuration unless you have a very good reason to do so. Log4j2 provides some very nice features that make it possible to do almost everything via a configuration file.
My best guess is that you want to use a dynamic file name that is somehow selected at runtime. If this is the case you can definitely do this using log4j2 lookups. In another answer I wrote an example that uses the system properties lookup. As you can see the file name is dynamic based on a system property rather than being static or hardcoded into the config file. There are many other lookups, so I suggest reading the manual carefully and choosing one that best fits your needs.
As for your question of how to send all logs to a file it's as simple as not specifying a console appender. As stated in the log4j2 manual:
Appenders are responsible for delivering LogEvents to their
destination.
Referring again to the other answer I wrote you'll also notice that the configuration does not use console appender and thus does not generate any console messages.
Since I do not see you creating a console appender I'm betting that the issue is the following: builder.setStatusLevel(Level.ALL);
This would appear to be setting the log4j2 status logger to a level of "ALL" meaning it's going to generate all of the internal log4j2 log messages. I would recommend using a level of "WARN" or "ERROR" but if you really want to make sure that messages are never sent to console you could set this to "OFF".
hi. I just don't want to have to pass my .jar file with the log4j2.xml file. Does make sense or I'm missing something here?
– joao.sauer
Nov 22 '18 at 9:35
I would say logging configuration is always the choice of the user of an application. You could provide a default configuration but ultimately whoever uses the jar should configure logging. Your responsibility is to inform the user how they can configure it. E.g. by telling them your code uses log4j2
– D.B.
Nov 22 '18 at 16:24
add a comment |
Without more details it's hard to give an exact answer, however, I will try to help point you in the right direction.
First, I would highly recommend that you do not use programmatic configuration unless you have a very good reason to do so. Log4j2 provides some very nice features that make it possible to do almost everything via a configuration file.
My best guess is that you want to use a dynamic file name that is somehow selected at runtime. If this is the case you can definitely do this using log4j2 lookups. In another answer I wrote an example that uses the system properties lookup. As you can see the file name is dynamic based on a system property rather than being static or hardcoded into the config file. There are many other lookups, so I suggest reading the manual carefully and choosing one that best fits your needs.
As for your question of how to send all logs to a file it's as simple as not specifying a console appender. As stated in the log4j2 manual:
Appenders are responsible for delivering LogEvents to their
destination.
Referring again to the other answer I wrote you'll also notice that the configuration does not use console appender and thus does not generate any console messages.
Since I do not see you creating a console appender I'm betting that the issue is the following: builder.setStatusLevel(Level.ALL);
This would appear to be setting the log4j2 status logger to a level of "ALL" meaning it's going to generate all of the internal log4j2 log messages. I would recommend using a level of "WARN" or "ERROR" but if you really want to make sure that messages are never sent to console you could set this to "OFF".
hi. I just don't want to have to pass my .jar file with the log4j2.xml file. Does make sense or I'm missing something here?
– joao.sauer
Nov 22 '18 at 9:35
I would say logging configuration is always the choice of the user of an application. You could provide a default configuration but ultimately whoever uses the jar should configure logging. Your responsibility is to inform the user how they can configure it. E.g. by telling them your code uses log4j2
– D.B.
Nov 22 '18 at 16:24
add a comment |
Without more details it's hard to give an exact answer, however, I will try to help point you in the right direction.
First, I would highly recommend that you do not use programmatic configuration unless you have a very good reason to do so. Log4j2 provides some very nice features that make it possible to do almost everything via a configuration file.
My best guess is that you want to use a dynamic file name that is somehow selected at runtime. If this is the case you can definitely do this using log4j2 lookups. In another answer I wrote an example that uses the system properties lookup. As you can see the file name is dynamic based on a system property rather than being static or hardcoded into the config file. There are many other lookups, so I suggest reading the manual carefully and choosing one that best fits your needs.
As for your question of how to send all logs to a file it's as simple as not specifying a console appender. As stated in the log4j2 manual:
Appenders are responsible for delivering LogEvents to their
destination.
Referring again to the other answer I wrote you'll also notice that the configuration does not use console appender and thus does not generate any console messages.
Since I do not see you creating a console appender I'm betting that the issue is the following: builder.setStatusLevel(Level.ALL);
This would appear to be setting the log4j2 status logger to a level of "ALL" meaning it's going to generate all of the internal log4j2 log messages. I would recommend using a level of "WARN" or "ERROR" but if you really want to make sure that messages are never sent to console you could set this to "OFF".
Without more details it's hard to give an exact answer, however, I will try to help point you in the right direction.
First, I would highly recommend that you do not use programmatic configuration unless you have a very good reason to do so. Log4j2 provides some very nice features that make it possible to do almost everything via a configuration file.
My best guess is that you want to use a dynamic file name that is somehow selected at runtime. If this is the case you can definitely do this using log4j2 lookups. In another answer I wrote an example that uses the system properties lookup. As you can see the file name is dynamic based on a system property rather than being static or hardcoded into the config file. There are many other lookups, so I suggest reading the manual carefully and choosing one that best fits your needs.
As for your question of how to send all logs to a file it's as simple as not specifying a console appender. As stated in the log4j2 manual:
Appenders are responsible for delivering LogEvents to their
destination.
Referring again to the other answer I wrote you'll also notice that the configuration does not use console appender and thus does not generate any console messages.
Since I do not see you creating a console appender I'm betting that the issue is the following: builder.setStatusLevel(Level.ALL);
This would appear to be setting the log4j2 status logger to a level of "ALL" meaning it's going to generate all of the internal log4j2 log messages. I would recommend using a level of "WARN" or "ERROR" but if you really want to make sure that messages are never sent to console you could set this to "OFF".
answered Nov 19 '18 at 14:55
D.B.D.B.
2,76621026
2,76621026
hi. I just don't want to have to pass my .jar file with the log4j2.xml file. Does make sense or I'm missing something here?
– joao.sauer
Nov 22 '18 at 9:35
I would say logging configuration is always the choice of the user of an application. You could provide a default configuration but ultimately whoever uses the jar should configure logging. Your responsibility is to inform the user how they can configure it. E.g. by telling them your code uses log4j2
– D.B.
Nov 22 '18 at 16:24
add a comment |
hi. I just don't want to have to pass my .jar file with the log4j2.xml file. Does make sense or I'm missing something here?
– joao.sauer
Nov 22 '18 at 9:35
I would say logging configuration is always the choice of the user of an application. You could provide a default configuration but ultimately whoever uses the jar should configure logging. Your responsibility is to inform the user how they can configure it. E.g. by telling them your code uses log4j2
– D.B.
Nov 22 '18 at 16:24
hi. I just don't want to have to pass my .jar file with the log4j2.xml file. Does make sense or I'm missing something here?
– joao.sauer
Nov 22 '18 at 9:35
hi. I just don't want to have to pass my .jar file with the log4j2.xml file. Does make sense or I'm missing something here?
– joao.sauer
Nov 22 '18 at 9:35
I would say logging configuration is always the choice of the user of an application. You could provide a default configuration but ultimately whoever uses the jar should configure logging. Your responsibility is to inform the user how they can configure it. E.g. by telling them your code uses log4j2
– D.B.
Nov 22 '18 at 16:24
I would say logging configuration is always the choice of the user of an application. You could provide a default configuration but ultimately whoever uses the jar should configure logging. Your responsibility is to inform the user how they can configure it. E.g. by telling them your code uses log4j2
– D.B.
Nov 22 '18 at 16:24
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53336964%2flog4j-programmatic-configure-to-only-save-in-file%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Could you please explain why do you need to do programmatic configuration? Generally this should be avoided unless absolutely necessary because it makes your code depend on the log4j2 implementation details rather than on the public API.
– D.B.
Nov 17 '18 at 6:57