1 package org.eclipse.jetty.util.log;
2 //========================================================================
3 //Copyright (c) 2006-2012 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 //The Eclipse Public License is available at
9 //http://www.eclipse.org/legal/epl-v10.html
10 //The Apache License v2.0 is available at
11 //http://www.opensource.org/licenses/apache2.0.php
12 //You may elect to redistribute this code under either of these licenses.
13 //========================================================================
14
15
16 /* ------------------------------------------------------------ */
17 /** Abstract Logger.
18 * Manages the atomic registration of the logger by name.
19 */
20 public abstract class AbstractLogger implements Logger
21 {
22 public final Logger getLogger(String name)
23 {
24 if (isBlank(name))
25 return this;
26
27 final String basename = getName();
28 final String fullname = (isBlank(basename) || Log.getRootLogger()==this)?name:(basename + "." + name);
29
30 Logger logger = Log.getLoggers().get(fullname);
31 if (logger == null)
32 {
33 Logger newlog = newLogger(fullname);
34
35 logger = Log.getMutableLoggers().putIfAbsent(fullname,newlog);
36 if (logger == null)
37 logger=newlog;
38 }
39
40 return logger;
41 }
42
43
44 protected abstract Logger newLogger(String fullname);
45
46 /**
47 * A more robust form of name blank test. Will return true for null names, and names that have only whitespace
48 *
49 * @param name
50 * the name to test
51 * @return true for null or blank name, false if any non-whitespace character is found.
52 */
53 private static boolean isBlank(String name)
54 {
55 if (name == null)
56 {
57 return true;
58 }
59 int size = name.length();
60 char c;
61 for (int i = 0; i < size; i++)
62 {
63 c = name.charAt(i);
64 if (!Character.isWhitespace(c))
65 {
66 return false;
67 }
68 }
69 return true;
70 }
71 }