类 Log4jConfigurer


  • @Deprecated
    public abstract class Log4jConfigurer
    extends Object
    已过时。
    as of Spring 4.2.1, in favor of Apache Log4j 2 (following Apache's EOL declaration for log4j 1.x)
    Convenience class that features simple methods for custom log4j configuration.

    Only needed for non-default log4j initialization, for example with a custom config location or a refresh interval. By default, log4j will simply read its configuration from a "log4j.properties" or "log4j.xml" file in the root of the classpath.

    For web environments, the analogous Log4jWebConfigurer class can be found in the web package, reading in its configuration from context-params in web.xml. In a J2EE web application, log4j is usually set up via Log4jConfigListener, delegating to Log4jWebConfigurer underneath.

    从以下版本开始:
    13.03.2003
    作者:
    Juergen Hoeller
    另请参阅:
    Log4jWebConfigurer, Log4jConfigListener
    • 方法详细资料

      • initLogging

        public static void initLogging​(String location)
                                throws FileNotFoundException
        已过时。
        Initialize log4j from the given file location, with no config file refreshing. Assumes an XML file in case of a ".xml" file extension, and a properties file otherwise.
        参数:
        location - the location of the config file: either a "classpath:" location (e.g. "classpath:myLog4j.properties"), an absolute file URL (e.g. "file:C:/log4j.properties), or a plain absolute path in the file system (e.g. "C:/log4j.properties")
        抛出:
        FileNotFoundException - if the location specifies an invalid file path
      • initLogging

        public static void initLogging​(String location,
                                       long refreshInterval)
                                throws FileNotFoundException
        已过时。
        Initialize log4j from the given location, with the given refresh interval for the config file. Assumes an XML file in case of a ".xml" file extension, and a properties file otherwise.

        Log4j's watchdog thread will asynchronously check whether the timestamp of the config file has changed, using the given interval between checks. A refresh interval of 1000 milliseconds (one second), which allows to do on-demand log level changes with immediate effect, is not unfeasible.

        WARNING: Log4j's watchdog thread does not terminate until VM shutdown; in particular, it does not terminate on LogManager shutdown. Therefore, it is recommended to not use config file refreshing in a production J2EE environment; the watchdog thread would not stop on application shutdown there.

        参数:
        location - the location of the config file: either a "classpath:" location (e.g. "classpath:myLog4j.properties"), an absolute file URL (e.g. "file:C:/log4j.properties), or a plain absolute path in the file system (e.g. "C:/log4j.properties")
        refreshInterval - interval between config file refresh checks, in milliseconds
        抛出:
        FileNotFoundException - if the location specifies an invalid file path
      • shutdownLogging

        public static void shutdownLogging()
        已过时。
        Shut down log4j, properly releasing all file locks.

        This isn't strictly necessary, but recommended for shutting down log4j in a scenario where the host VM stays alive (for example, when shutting down an application in a J2EE environment).

      • setWorkingDirSystemProperty

        public static void setWorkingDirSystemProperty​(String key)
        已过时。
        Set the specified system property to the current working directory.

        This can be used e.g. for test environments, for applications that leverage Log4jWebConfigurer's "webAppRootKey" support in a web environment.

        参数:
        key - system property key to use, as expected in Log4j configuration (for example: "demo.root", used as "${demo.root}/WEB-INF/demo.log")
        另请参阅:
        Log4jWebConfigurer