-1

I am using apache log4j into my application, this is an independent ear I am deploying. logs are getting displayed. But at runtime I am trying to change the Log level, this is not reflecting into my application. Ex : 2 logger I am using info() and error(). When deploying application and hitting application I am getting both logs into my log file because into properties file I configured log level as Debug. Now aruntime I am changing the Log level to ERROR. and Hitting the application then also it displays both info and error. But ideally it should display error log only.

Any solutions for this problem .

Thanks In Advance

DV82XL
  • 5,350
  • 5
  • 30
  • 59
Neeraj
  • 171
  • 2
  • 11
  • Does this answer your question? [Dynamically Changing log4j log level](https://stackoverflow.com/questions/4598702/dynamically-changing-log4j-log-level) – DV82XL Aug 18 '20 at 12:18
  • DV82XL as per the link only thing I was missing is logger.setLevel(Level.INFO) and logger.setLevel(Level.ERROR) , but still this is not working for me. – Neeraj Aug 18 '20 at 13:36
  • Can you update your question to specify exactly HOW you are attempting to change the log level during runtime? Are you updating the `log4j.properties` file (if so, post its contents) or making an API call (if so, provide the exact call)? Finally, would you be willing to upgrade to log4j2? It has built-in monitoring. See https://stackoverflow.com/questions/2115900/is-it-possible-to-reload-log4j-xml-log4j-properties-file-dynamically-in-tomcat/. – DV82XL Aug 18 '20 at 13:46
  • I am using some standalone.xml (my server configuration file)where my logging configurations present. Here only I am changing the logging level – Neeraj Aug 18 '20 at 13:50
  • My Server is up and I am manually editing the standalone.xml . – Neeraj Aug 18 '20 at 14:08

1 Answers1

0

As you mentioned in your comment, you are modifying standalone.xml directly during runtime. This is bad practice, since Wildfly may revert (and ignore) your changes. If you need to make changes to your settings, use the Wildfly CLI or web console.

You can call the Wildfly CLI like this:

/opt/jboss/jboss-eap-<version>/bin/jboss-cli.sh --controller=<ip>:<port> --connect
/subsystem=logging/root-logger=ROOT:write-attribute(name="level", value="ERROR")

If this doesn't work, Wildfly may be using the application (war/jar) log settings, e.g. defined in log4j.properties, so you need to disable application log configuration and create a logging profile. This is somewhat involved, so I won't repeat the steps here. Read Changing Logging Configurations at Runtime on Wildfly Server and Change Log Level at Runtime with Wildfly for more information.

Once you have setup your log profile, you can change log settings using the Wildfly CLI during runtime without reloading the server, like this:

/subsystem=logging/logging-profile=DEMO/root-logger=ROOT:write-attribute(name="level", value="ERROR")

Type exit to leave the CLI.

DV82XL
  • 5,350
  • 5
  • 30
  • 59
  • DV82XL jboss-cli.sh is failing to change logging level, triggered the command with mine server ip and port but throwing some error '(' missing . – Neeraj Aug 19 '20 at 09:25
  • @Neeraj Please add an EDIT section at the end of your question showing the exact command you called and the complete error message. Otherwise, I can't predict what you're doing/seeing. Also, if you find an answer useful because it provided some insight, upvote it. If the answer solves your question, check the green check mark. Thanks! – DV82XL Aug 19 '20 at 12:44
  • i used below command : /opt/jboss/jboss-eap-6.4/bin/jboss-cli.sh --controller=10.10.20.198:9090 --connect /subsystem=logging/root-logger=ROOT:write-attribute(name="level", value="ERROR"). Also i tried various approach from refered links. None of them worked for me :( , I tried updating via getting the configuration (https://stackoverflow.com/a/32019244/10017725) and then updating context but still it is asking for restart. I am changing both in my logging.properties and standalone.xml but it no fruitful outcome – Neeraj Aug 19 '20 at 12:54
  • Update this new information directly in your question above. I won't read it in a comment. Thank you for understanding. – DV82XL Aug 19 '20 at 17:02