ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/util/uk/org/iscream/cms/util/FormatName.java
Revision: 1.13
Committed: Sat May 18 18:16:03 2002 UTC (21 years, 11 months ago) by tdb
Branch: MAIN
Changes since 1.12: +21 -2 lines
Log Message:
i-scream is now licensed under the GPL. I've added the GPL headers to every
source file, and put a full copy of the license in the appropriate places.
I think I've covered everything. This is going to be a mad commit ;)

File Contents

# Content
1 /*
2 * i-scream central monitoring system
3 * Copyright (C) 2000-2002 i-scream
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 */
19
20 //---PACKAGE DECLARATION---
21 package uk.org.iscream.cms.server.util;
22
23 //---IMPORTS---
24 import java.util.Date;
25 import java.text.DateFormat;
26 import java.util.Locale;
27
28 /**
29 * This class provides static methods to format the
30 * name of a calling object. It's main use is by
31 * the various objects within the system to create
32 * a toString String to send to the logger.
33 *
34 * @author $Author: tdb $
35 * @version $Id: FormatName.java,v 1.12 2001/05/29 17:02:35 tdb Exp $
36 */
37 public class FormatName {
38
39 //---FINAL ATTRIBUTES---
40
41 /**
42 * An array of names of verbosity levels.
43 * Thus logging messages are now "classed" by the level
44 */
45 private final static String[] VERBOSITY_NAMES = {"FATAL ", "ERROR ", "WARNING", "SYSMSG ", "SYSINIT", "DEBUG "};
46
47 //---STATIC METHODS---
48
49 /**
50 * This method takes a set of information about the calling
51 * class and constructs a tidy String name to be returned.
52 * This is of use to the override of the toString() as
53 * implemented by most of the iscream objects.
54 *
55 * @param friendlyName the configured name of the instance of the calling component the class is in (eg "filter1")
56 * @param className the class name of the calling class, as obtained by getClass().getName()
57 * @param revision the CVS Revision number for the calling class
58 *
59 * @return an iscream standard name to be used as a toString()
60 */
61 public static String getName(String friendlyName, String className, String revision) {
62 if (friendlyName == null && className == null) {
63 return "{static(v" + revision.substring(11, revision.length() - 2) + ")}";
64 } else if (friendlyName == null) {
65 return "{"+ tidyClassName(className) + "(v" + revision.substring(11, revision.length() - 2) + ")}";
66 } else if (className == null) {
67 return friendlyName + "{static(v" + revision.substring(11, revision.length() - 2) + ")}";
68 } else {
69 return friendlyName + "{"+ tidyClassName(className) + "(v" + revision.substring(11, revision.length() - 2) + ")}";
70 }
71 }
72
73 /**
74 * This method generates a nicely formatted line for the log,
75 * including the date/time and the source of the message. The date
76 * and time are formatted using the DateFormat class, and the source
77 * class is formatted using the toString() method found in every
78 * source file. This is then prepended to the message and returned.
79 *
80 * @param source A string representation of the calling object.
81 * @param verbosity The verbosity of the message.
82 * @param message The message to be logged.
83 * @return The string to be written to the log.
84 */
85 public static String formatLogLine(String source, int verbosity, String message){
86 String date = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM).format(new Date());
87 return "[" + date + "] [" + VERBOSITY_NAMES[verbosity] + "] " + source + ": " + message;
88 }
89
90 /**
91 * If the class name begins with uk.org.iscream.cms.server
92 * this method will trim it off, otherwise it
93 * leaves the string unchanged.
94 *
95 * @param className the name of a class
96 *
97 * @return the tidy version of it
98 */
99 private static String tidyClassName(String className) {
100 String prefix = "uk.org.iscream.cms.server";
101 if (className.startsWith(prefix)) {
102 return className.substring(prefix.length()+1);
103 }
104 return className;
105 }
106
107 //---CONSTRUCTORS---
108
109 /**
110 * A private constructor ensures an instance of this
111 * class CANNOT be created.
112 */
113 private FormatName() {
114 // do nothing on purpose!
115 }
116
117 //---PUBLIC METHODS---
118
119 //---PRIVATE METHODS---
120
121 //---ACCESSOR/MUTATOR METHODS---
122
123 //---ATTRIBUTES---
124
125 //---STATIC ATTRIBUTES---
126
127 }