Configuring logging
In the Creating a Roo project recipe, you saw that when you create a new project, a log4j.properties
file is automatically created with default logging configuration. In most real projects, you'd like to customize the default logging configuration. By default, the log4j.properties
file configures root logger at ERROR
level and logging is not enabled for the project.
In this recipe, we will look at the logging setup
command to modify the logging configuration.
Getting ready
Start the Roo shell from the C:\roo-cookbook\ch01-recipe
directory, which contains the flight-app
Roo project.
How to do it...
Using the logging
setup
command you can specify the logging level and the package to which it applies, as shown in the following steps:
The following
logging
setup
commands are used to change the logging level of rootLogger toDEBUG
(which isERROR
by default) and enableDEBUG
level logging for all classes in theflight-app
application:roo> logging setup --level DEBUG --package ROOT Updated SRC_MAIN_RESOURCES\log4j.properties roo> logging setup --level DEBUG --package PROJECT Updated SRC_MAIN_RESOURCES\log4j.properties
As the output from the command execution suggests, some changes have been made by Roo to the
log4j.properties
file.Tip
Keep an eye on the output of a command
When a Roo command is executed, it displays information about what files and directories have been created or which files have been updated. This can be helpful if you want to check the code that is generated on execution of a command.
To confirm that the changes have been made to the
log4j.properties
, you can either view it directly by opening the file or you can use theproperties
list
command (explained in the next recipe).
How it works...
The logging
setup
command is processed by the Logging add-on of Spring Roo. The following table describes the arguments that the logging
setup
command accepts:
Argument |
Purpose |
---|---|
|
This is a mandatory argument, which identifies the logging level. It can only take one of the pre-defined values, like |
|
This is an optional argument, which specifies the package to which the logging level applies. It can only take one of the pre-defined values, such as |
There's more...
As of Spring Roo 1.1.3, using the logging
setup
command you can't specify a custom package name as the value of the package
argument; therefore, you can set a custom package name either by using the properties
set
command (explained later in this chapter) or by directly editing the log4j.properties
file.
See also
The Viewing properties defined in a properties file, Removing a property defined in a properties file, and Adding properties to a properties file recipes show how you can manage properties files in your Roo project.