All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.eclipse.jetty.util.log.JavaUtilLog Maven / Gradle / Ivy

Go to download

Ehcache is an open source, standards-based cache used to boost performance, offload the database and simplify scalability. Ehcache is robust, proven and full-featured and this has made it the most widely-used Java-based cache.

There is a newer version: 2.10.9.2
Show newest version
//
//  ========================================================================
//  Copyright (c) 1995-2018 Mort Bay Consulting Pty. Ltd.
//  ------------------------------------------------------------------------
//  All rights reserved. This program and the accompanying materials
//  are made available under the terms of the Eclipse Public License v1.0
//  and Apache License v2.0 which accompanies this distribution.
//
//      The Eclipse Public License is available at
//      http://www.eclipse.org/legal/epl-v10.html
//
//      The Apache License v2.0 is available at
//      http://www.opensource.org/licenses/apache2.0.php
//
//  You may elect to redistribute this code under either of these licenses.
//  ========================================================================
//

package org.eclipse.jetty.util.log;

import java.net.URL;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.logging.Level;
import java.util.logging.LogManager;
import java.util.logging.LogRecord;

import org.eclipse.jetty.util.Loader;

/**
 * 

* Implementation of Jetty {@link Logger} based on {@link java.util.logging.Logger}. *

* *

* You can also set the logger level using * standard java.util.logging configuration. *

* * Configuration Properties: *
*
${name|hierarchy}.LEVEL=(ALL|DEBUG|INFO|WARN|OFF)
*
* Sets the level that the Logger should log at.
* Names can be a package name, or a fully qualified class name.
* Default: The default from the java.util.logging mechanism/configuration *
*
org.eclipse.jetty.util.log.javautil.PROPERTIES=<property-resource-name>
*
If set, it is used as a classpath resource name to find a java.util.logging * property file. *
* Default: null *
*
org.eclipse.jetty.util.log.javautil.SOURCE=(true|false)
*
Set the LogRecord source class and method for JavaUtilLog.
* Default: true *
*
org.eclipse.jetty.util.log.SOURCE=(true|false)
*
Set the LogRecord source class and method for all Loggers.
* Default: depends on Logger class *
*
*/ public class JavaUtilLog extends AbstractLogger { private final static String THIS_CLASS= JavaUtilLog.class.getName(); private final static boolean __source = Boolean.parseBoolean(Log.__props.getProperty("org.eclipse.jetty.util.log.SOURCE", Log.__props.getProperty("org.eclipse.jetty.util.log.javautil.SOURCE","true"))); private static boolean _initialized=false; private Level configuredLevel; private java.util.logging.Logger _logger; public JavaUtilLog() { this("org.eclipse.jetty.util.log.javautil"); } public JavaUtilLog(String name) { synchronized (JavaUtilLog.class) { if (!_initialized) { _initialized=true; final String properties=Log.__props.getProperty("org.eclipse.jetty.util.log.javautil.PROPERTIES",null); if (properties!=null) { AccessController.doPrivileged(new PrivilegedAction() { @Override public Object run() { try { URL props = Loader.getResource(properties); if (props != null) LogManager.getLogManager().readConfiguration(props.openStream()); } catch(Throwable e) { System.err.println("[WARN] Error loading logging config: " + properties); e.printStackTrace(System.err); } return null; } }); } } } _logger = java.util.logging.Logger.getLogger(name); switch(lookupLoggingLevel(Log.__props,name)) { case LEVEL_ALL: _logger.setLevel(Level.ALL); break; case LEVEL_DEBUG: _logger.setLevel(Level.FINE); break; case LEVEL_INFO: _logger.setLevel(Level.INFO); break; case LEVEL_WARN: _logger.setLevel(Level.WARNING); break; case LEVEL_OFF: _logger.setLevel(Level.OFF); break; case LEVEL_DEFAULT: default: break; } configuredLevel = _logger.getLevel(); } @Override public String getName() { return _logger.getName(); } protected void log(Level level,String msg,Throwable thrown) { LogRecord record = new LogRecord(level,msg); if (thrown!=null) record.setThrown(thrown); record.setLoggerName(_logger.getName()); if (__source) { StackTraceElement[] stack = new Throwable().getStackTrace(); for (int i=0;i