]> WPIA git - gigi.git/blob - lib/jetty/org/eclipse/jetty/util/log/AbstractLogger.java
Importing upstream Jetty jetty-9.2.1.v20140609
[gigi.git] / lib / jetty / org / eclipse / jetty / util / log / AbstractLogger.java
1 //
2 //  ========================================================================
3 //  Copyright (c) 1995-2014 Mort Bay Consulting Pty. Ltd.
4 //  ------------------------------------------------------------------------
5 //  All rights reserved. This program and the accompanying materials
6 //  are made available under the terms of the Eclipse Public License v1.0
7 //  and Apache License v2.0 which accompanies this distribution.
8 //
9 //      The Eclipse Public License is available at
10 //      http://www.eclipse.org/legal/epl-v10.html
11 //
12 //      The Apache License v2.0 is available at
13 //      http://www.opensource.org/licenses/apache2.0.php
14 //
15 //  You may elect to redistribute this code under either of these licenses.
16 //  ========================================================================
17 //
18
19 package org.eclipse.jetty.util.log;
20
21
22 /* ------------------------------------------------------------ */
23 /** Abstract Logger.
24  * Manages the atomic registration of the logger by name.
25  */
26 public abstract class AbstractLogger implements Logger
27 {
28     @Override
29     public final Logger getLogger(String name)
30     {
31         if (isBlank(name))
32             return this;
33
34         final String basename = getName();
35         final String fullname = (isBlank(basename) || Log.getRootLogger()==this)?name:(basename + "." + name);
36         
37         Logger logger = Log.getLoggers().get(fullname);
38         if (logger == null)
39         {
40             Logger newlog = newLogger(fullname);
41             
42             logger = Log.getMutableLoggers().putIfAbsent(fullname,newlog);
43             if (logger == null)
44                 logger=newlog;
45         }
46
47         return logger;
48     }
49     
50
51     protected abstract Logger newLogger(String fullname);
52
53     /**
54      * A more robust form of name blank test. Will return true for null names, and names that have only whitespace
55      *
56      * @param name
57      *            the name to test
58      * @return true for null or blank name, false if any non-whitespace character is found.
59      */
60     private static boolean isBlank(String name)
61     {
62         if (name == null)
63         {
64             return true;
65         }
66         int size = name.length();
67         char c;
68         for (int i = 0; i < size; i++)
69         {
70             c = name.charAt(i);
71             if (!Character.isWhitespace(c))
72             {
73                 return false;
74             }
75         }
76         return true;
77     }
78     
79     public void debug(String msg, long arg)
80     {
81         if (isDebugEnabled())
82             debug(msg,new Long(arg));
83     }
84 }