Mercurial Hosting > luan
comparison src/org/eclipse/jetty/util/log/AbstractLogger.java @ 802:3428c60d7cfc
replace jetty jars with source
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Wed, 07 Sep 2016 21:15:48 -0600 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
801:6a21393191c1 | 802:3428c60d7cfc |
---|---|
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 public final Logger getLogger(String name) | |
29 { | |
30 if (isBlank(name)) | |
31 return this; | |
32 | |
33 final String basename = getName(); | |
34 final String fullname = (isBlank(basename) || Log.getRootLogger()==this)?name:(basename + "." + name); | |
35 | |
36 Logger logger = Log.getLoggers().get(fullname); | |
37 if (logger == null) | |
38 { | |
39 Logger newlog = newLogger(fullname); | |
40 | |
41 logger = Log.getMutableLoggers().putIfAbsent(fullname,newlog); | |
42 if (logger == null) | |
43 logger=newlog; | |
44 } | |
45 | |
46 return logger; | |
47 } | |
48 | |
49 | |
50 protected abstract Logger newLogger(String fullname); | |
51 | |
52 /** | |
53 * A more robust form of name blank test. Will return true for null names, and names that have only whitespace | |
54 * | |
55 * @param name | |
56 * the name to test | |
57 * @return true for null or blank name, false if any non-whitespace character is found. | |
58 */ | |
59 private static boolean isBlank(String name) | |
60 { | |
61 if (name == null) | |
62 { | |
63 return true; | |
64 } | |
65 int size = name.length(); | |
66 char c; | |
67 for (int i = 0; i < size; i++) | |
68 { | |
69 c = name.charAt(i); | |
70 if (!Character.isWhitespace(c)) | |
71 { | |
72 return false; | |
73 } | |
74 } | |
75 return true; | |
76 } | |
77 } |