此内容没有您所选择的语言版本。
12.5. Logging Profiles
12.5.1. About Logging Profiles 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
Important
Logging profiles are only available in version 6.1.0 and later. They cannot be configured using the management console.
Logging profiles are independent sets of logging configuration that can be assigned to deployed applications. As with the regular logging subsystem, a logging profile can define handlers, categories and a root logger but cannot refer to configuration in other profiles or the main logging subsystem. The design of logging profiles mimics the logging subsystem for ease of configuration.
The use of logging profiles allows administrators to create logging configuration that are specific to one or more applications without affecting any other logging configuration. Because each profile is defined in the server configuration, the logging configuration can be changed without requiring that the affected applications be redeployed.
Each logging profile can have the following configuration:
- A unique name. This is required.
- Any number of log handlers.
- Any number of log categories.
- Up to one root logger.
An application can specify a logging profile to use in its
MANIFEST.MF
file, using the logging-profile
attribute.
12.5.2. Create a new Logging Profile using the CLI 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
A new logging profile can be created using the CLI command below, replacing NAME with your required profile name:
/subsystem=logging/logging-profile=NAME:add
/subsystem=logging/logging-profile=NAME:add
This will create a new empty profile to which handlers, categories and a root logger can be added.
12.5.3. Configuring a Logging Profile using the CLI 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
A logging profile can be configured with log handlers, categories and a root logger using almost exactly the same syntax as when using the main logging subsystem.
There are only two differences between configuring the main logging subsystem and the logging profile:
- The root configuration path is
/subsystem=logging/logging-profile=NAME
- A logging profile cannot contain other logging profiles.
Refer to the appropriate logging management task:
Example 12.79. Creating and Configuring a Logging Profile
Creating a logging profile and adding a category and file log handler.
- Create the profile:
/subsystem=logging/logging-profile=accounts-app-profile:add
/subsystem=logging/logging-profile=accounts-app-profile:add
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Create file handler
/subsystem=logging/logging-profile=accounts-app-profile/file-handler=ejb-trace-file:add(file={path=>"ejb-trace.log", "relative-to"=>"jboss.server.log.dir"})
/subsystem=logging/logging-profile=accounts-app-profile/file-handler=ejb-trace-file:add(file={path=>"ejb-trace.log", "relative-to"=>"jboss.server.log.dir"})
Copy to Clipboard Copied! Toggle word wrap Toggle overflow /subsystem=logging/logging-profile=accounts-app-profile/file-handler=ejb-trace-file:write-attribute(name="level", value="DEBUG")
/subsystem=logging/logging-profile=accounts-app-profile/file-handler=ejb-trace-file:write-attribute(name="level", value="DEBUG")
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Create logger category
/subsystem=logging/logging-profile=accounts-app-profile/logger=com.company.accounts.ejbs:add(level=TRACE)
/subsystem=logging/logging-profile=accounts-app-profile/logger=com.company.accounts.ejbs:add(level=TRACE)
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Assign file handler to category
/subsystem=logging/logging-profile=accounts-app-profile/logger=com.company.accounts.ejbs:add-handler(name="ejb-trace-file")
/subsystem=logging/logging-profile=accounts-app-profile/logger=com.company.accounts.ejbs:add-handler(name="ejb-trace-file")
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
12.5.4. Specify a Logging Profile in an Application 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
An application specifies the logging profile to use in its
MANIFEST.MF
file.
Prerequisites:
- You must know the name of the logging profile that has been setup on the server for this application to use. Ask your server administrator for the name of the profile to use.
Procedure 12.9. Add Logging Profile configuration to an Application
Edit
MANIFEST.MF
If your application does not have aMANIFEST.MF
file: create one with the following content, replacing NAME with the required profile name.Manifest-Version: 1.0 Logging-Profile: NAME
Manifest-Version: 1.0 Logging-Profile: NAME
Copy to Clipboard Copied! Toggle word wrap Toggle overflow If your application already has aMANIFEST.MF
file: add the following line to it, replacing NAME with the required profile name.Logging-Profile: NAME
Logging-Profile: NAME
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Note
If you are using Maven and the
maven-war-plugin
, you can put your MANIFEST.MF file in src/main/resources/META-INF/
and add the following configuration to your pom.xml
file.
When the application is deployed it will use the configuration in the specified logging profile for its log messages.
12.5.5. Example Logging Profile Configuration 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
This example shows the configuration of a logging profile and the application that makes use of it. The CLI session is shown, the XML configuration that is generated, and the
MANIFEST.MF
file of the application.
The logging profile example has the following characteristics:
- The Name is
accounts-app-profile
. - The Log Category is
com.company.accounts.ejbs
. - The Log level
TRACE
. - The Log handler is a file handler using the file
ejb-trace.log
.
Example 12.80. CLI session
Example 12.81. XML Configuration
Example 12.82. Application MANIFEST.MF file
Manifest-Version: 1.0 Logging-Profile: accounts-app-profile
Manifest-Version: 1.0
Logging-Profile: accounts-app-profile