001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache license, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the license for the specific language governing permissions and
015 * limitations under the license.
016 */
017package org.apache.logging.log4j.core.config;
018
019import java.io.Serializable;
020
021import org.apache.logging.log4j.Level;
022import org.apache.logging.log4j.core.Appender;
023import org.apache.logging.log4j.core.Layout;
024import org.apache.logging.log4j.core.appender.ConsoleAppender;
025import org.apache.logging.log4j.core.layout.PatternLayout;
026import org.apache.logging.log4j.util.PropertiesUtil;
027
028/**
029 * The default configuration writes all output to the Console using the default logging level. You configure default
030 * logging level by setting the system property "org.apache.logging.log4j.level" to a level name. If you do not
031 * specify the property, Log4j uses the ERROR Level. Log Events will be printed using the basic formatting provided
032 * by each Message.
033 */
034public class DefaultConfiguration extends BaseConfiguration {
035
036    /**
037     * The name of the default configuration.
038     */
039    public static final String DEFAULT_NAME = "Default";
040    /**
041     * The System Property used to specify the logging level.
042     */
043    public static final String DEFAULT_LEVEL = "org.apache.logging.log4j.level";
044
045    /**
046     * Constructor to create the default configuration.
047     */
048    public DefaultConfiguration() {
049
050        setName(DEFAULT_NAME);
051        final Layout<? extends Serializable> layout =
052                PatternLayout.createLayout("%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n", null, null, null, null, null);
053        final Appender appender =
054                ConsoleAppender.createAppender(layout, null, "SYSTEM_OUT", "Console", "false", "true");
055        appender.start();
056        addAppender(appender);
057        final LoggerConfig root = getRootLogger();
058        root.addAppender(appender, null, null);
059
060        final String levelName = PropertiesUtil.getProperties().getStringProperty(DEFAULT_LEVEL);
061        final Level level = levelName != null && Level.valueOf(levelName) != null ?
062            Level.valueOf(levelName) : Level.ERROR;
063        root.setLevel(level);
064    }
065
066    @Override
067    protected void doConfigure() {
068    }
069}