test/jdk/java/util/logging/LogManager/Configuration/rootLoggerHandlers/custom/GlobalHandler.java
author dfuchs
Fri, 26 Jan 2018 14:15:09 +0000
changeset 48674 e2a7856edfba
permissions -rw-r--r--
8195096: Exception printed on console with custom LogManager on starting Apache Tomcat Summary: make sure that loadLoggerHandler for ".handler" is called only from within addLogger Reviewed-by: mchung
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
48674
e2a7856edfba 8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff changeset
     1
/*
e2a7856edfba 8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff changeset
     2
 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
e2a7856edfba 8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
e2a7856edfba 8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff changeset
     4
 *
e2a7856edfba 8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
e2a7856edfba 8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
e2a7856edfba 8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff changeset
     7
 * published by the Free Software Foundation.
e2a7856edfba 8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff changeset
     8
 *
e2a7856edfba 8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
e2a7856edfba 8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e2a7856edfba 8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
e2a7856edfba 8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
e2a7856edfba 8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff changeset
    13
 * accompanied this code).
e2a7856edfba 8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff changeset
    14
 *
e2a7856edfba 8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
e2a7856edfba 8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
e2a7856edfba 8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e2a7856edfba 8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff changeset
    18
 *
e2a7856edfba 8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
e2a7856edfba 8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
e2a7856edfba 8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff changeset
    21
 * questions.
e2a7856edfba 8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff changeset
    22
 */
e2a7856edfba 8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff changeset
    23
package custom;
e2a7856edfba 8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff changeset
    24
e2a7856edfba 8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff changeset
    25
import java.util.concurrent.atomic.AtomicLong;
e2a7856edfba 8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff changeset
    26
e2a7856edfba 8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff changeset
    27
/**
e2a7856edfba 8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff changeset
    28
 *
e2a7856edfba 8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff changeset
    29
 * @author danielfuchs
e2a7856edfba 8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff changeset
    30
 */
e2a7856edfba 8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff changeset
    31
public class GlobalHandler extends java.util.logging.ConsoleHandler {
e2a7856edfba 8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff changeset
    32
e2a7856edfba 8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff changeset
    33
    public static final AtomicLong IDS = new AtomicLong();
e2a7856edfba 8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff changeset
    34
    public final long id = IDS.incrementAndGet();
e2a7856edfba 8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff changeset
    35
    public GlobalHandler() {
e2a7856edfba 8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff changeset
    36
        System.out.println("GlobalHandler(" + id + ") created");
e2a7856edfba 8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff changeset
    37
        //new Exception("GlobalHandler").printStackTrace();
e2a7856edfba 8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff changeset
    38
    }
e2a7856edfba 8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff changeset
    39
e2a7856edfba 8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff changeset
    40
    @Override
e2a7856edfba 8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff changeset
    41
    public void close() {
e2a7856edfba 8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff changeset
    42
        System.out.println("GlobalHandler(" + id + ") closed");
e2a7856edfba 8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff changeset
    43
        super.close();
e2a7856edfba 8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff changeset
    44
    }
e2a7856edfba 8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff changeset
    45
e2a7856edfba 8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff changeset
    46
    @Override
e2a7856edfba 8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff changeset
    47
    public String toString() {
e2a7856edfba 8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff changeset
    48
        return this.getClass().getName() + '(' + id + ')';
e2a7856edfba 8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff changeset
    49
    }
e2a7856edfba 8195096: Exception printed on console with custom LogManager on starting Apache Tomcat
dfuchs
parents:
diff changeset
    50
}