引言
官方配置文档:
https://logging.apache.org/log4j/2.x/manual/filters.html
<Configuration>
节点
<Configuration>
Parameters
Attribute Name | Description | |
---|---|---|
advertiser | (Optional) The Advertiser plugin name which will be used to advertise individual FileAppender or SocketAppender configurations. The only Advertiser plugin provided is ‘multicastdns”. | |
dest | Either “err” for stderr, “out” for stdout, a file path, or a URL. | |
|
设置配置文件的
时间的,单位是秒 The minimum amount of time, in seconds, that must elapse before the file configuration is checked for changes. Log4j has the ability to
to the configuration file and
.for example,
mean the configuration file will be checked for changes only after at least
have elapsed. The
interval is 5 seconds. |
|
|
The
of the configuration. |
|
packages |
Use of the packages attribute is deprecated and will be removed in Log4j 3.0. Plugins should be processed with the Log4j annotation processor. A comma separated list of package names to search for plugins. Plugins are only loaded once per classloader so changing this value may not have any effect upon reconfiguration. |
|
schema | Identifies the location for the classloader to located the XML Schema to use to validate the configuration. Only valid when strict is set to true. If not set no schema validation will take place. | |
shutdownHook | Specifies whether or not Log4j should automatically shutdown when the JVM shuts down. The shutdown hook is enabled by default but may be disabled by setting this attribute to “disable” | |
shutdownTimeout |
Specifies how many milliseconds appenders and background tasks will get to shutdown when the JVM shuts down. Default is zero which mean that each appender uses its default timeout, and don’t wait for background tasks. Not all appenders will honor this, it is a hint and not an absolute guarantee that the shutdown procedure will not take longer. Setting this too low increase the risk of losing outstanding log events not yet written to the final destination. See LoggerContext.stop(long, java.util.concurrent.TimeUnit) . (Not used if
is set to “disable”.) |
|
|
指定log4j本身的打印日志的级别 The level of
that should
. Valid values for this attribute are “off”, “trace”, “debug”, “info”, “warn”, “error”, “fatal”, and “all”. Log4j will
to the status logger. Setting
is one of the first tools available to you if you need to
.(Alternatively, setting
will also
to the
, including
that took place
.) |
|
strict | Enables the use of the strict XML format. Not supported in JSON configurations. | |
verbose | Enables diagnostic information while loading plugins. |
场景1:
<!--设置log4j2自身内部的信息输出级别为info-->
<!--Log4j每隔10秒自动检测修改配置文件和重新配置本身,不需要重启服务-->
<Configuration status="info" monitorInterval="10">
</Configuration>
<!--日志级别以及优先级排序: OFF > FATAL > ERROR > WARN > INFO > DEBUG > TRACE > ALL-->