001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: *
023: * Free Software Foundation, Inc.
024: * 59 Temple Place, Suite 330
025: * Boston, MA 02111-1307 USA
026: *
027: * @author Scott Ferguson
028: */
029:
030: package com.caucho.log;
031:
032: import com.caucho.config.ConfigException;
033: import com.caucho.util.L10N;
034:
035: import javax.annotation.PostConstruct;
036: import java.util.logging.Level;
037: import java.util.logging.Logger;
038:
039: /**
040: * Environment-specific java.util.logging.Logger configuration.
041: */
042: public class LoggerConfig {
043: private static final L10N L = new L10N(LoggerConfig.class);
044:
045: private Logger _logger;
046: private Level _level = Level.INFO;
047: private Boolean _useParentHandlers;
048:
049: /**
050: * Sets the name of the logger to configure.
051: */
052: public void setName(String name) {
053: _logger = Logger.getLogger(name);
054: }
055:
056: /**
057: * Sets the use-parent-handlers
058: */
059: public void setUseParentHandlers(boolean useParentHandlers) {
060: _useParentHandlers = new Boolean(useParentHandlers);
061: }
062:
063: /**
064: * Sets the output level.
065: */
066: public void setLevel(String level) throws ConfigException {
067: if (level.equals("off"))
068: _level = Level.OFF;
069: else if (level.equals("severe"))
070: _level = Level.SEVERE;
071: else if (level.equals("warning"))
072: _level = Level.WARNING;
073: else if (level.equals("info"))
074: _level = Level.INFO;
075: else if (level.equals("config"))
076: _level = Level.CONFIG;
077: else if (level.equals("fine"))
078: _level = Level.FINE;
079: else if (level.equals("finer"))
080: _level = Level.FINER;
081: else if (level.equals("finest"))
082: _level = Level.FINEST;
083: else if (level.equals("all"))
084: _level = Level.ALL;
085: else
086: throw new ConfigException(
087: L
088: .l(
089: "`{0}' is an unknown log level. Log levels are:\noff - disable logging\nsevere - severe errors only\nwarning - warnings\ninfo - information\nconfig - configuration\nfine - fine debugging\nfiner - finer debugging\nfinest - finest debugging\nall - all debugging",
090: level));
091: }
092:
093: /**
094: * Initialize the logger.
095: */
096: @PostConstruct
097: public void init() {
098: if (_level != null)
099: _logger.setLevel(_level);
100:
101: if (_useParentHandlers != null)
102: _logger.setUseParentHandlers(_useParentHandlers
103: .booleanValue());
104: }
105: }
|