CLI Recipe: create a Logger with AS7

User Rating: 0 / 5

Star InactiveStar InactiveStar InactiveStar InactiveStar Inactive
 

The following sample script can be added to  your CLI scratchbook when you need to add a Logger on the fly for one package contained in your application

GOAL: create a custom logger for the package classes named com.sample. The logging information will be written in a custom File Handler that writes information in the file jboss.server.log.dir/customfile.log

In order to do that, we will at first:

  • Create a new logger "com.sample"
  • Define its logging level
  • Create the CustomFileHandler
  • Assign the CustomFileHandler the the "com.sample" logger
connect
batch
/subsystem=logging/logger=com.sample:add   
/subsystem=logging/logger=com.sample:write-attribute(name="level", value="DEBUG")
/subsystem=logging/file-handler=CustomFileHandler:add(file={"path"=>"customfile.log","relative-to"=>"jboss.server.log.dir"})
/subsystem=logging/logger=com.sample:assign-handler(name="CustomFileHandler")

run-batch
:reload

 Additionally, you might choose to re-use or not the root handler for your CustomFileHandler. With the following code we are not going to use the root handler:

/subsystem=logging/logger=com.sample:write-attribute(name="use-parent-handlers", value="false")

Advertisement

Related articles available on mastertheboss.com

How do I get the list of MBeans with twiddle?

  JBoss provides a simple command line tool that allows for inte

How to count active session with twiddle ?

  There are some well known alternatives to count the number of

How do I run garbage collector from shell?

  You can suggest JBoss to run the garbage collector in differen

How do I check my application status from shell?

  This is a two process step: at first you need to retrieve the

How do you shut down multiple JBoss instances?

  Supposing you have configured 2 instances of JBoss, one on por

twiddle reference guide

Please note: twiddle is not available any more as default Command