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
(Generate patch)

Comparing projects/cms/source/util/uk/org/iscream/cms/util/FormatName.java (file contents):
Revision 1.2 by ajm, Fri Dec 8 11:40:08 2000 UTC vs.
Revision 1.13 by tdb, Sat May 18 18:16:03 2002 UTC

# Line 1 | Line 1
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.ac.ukc.iscream.util;
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
# Line 16 | Line 38 | 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      /**
# Line 31 | Line 59 | public class FormatName {
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) {
63 <            return  "{"+ className + "}(" + revision.substring(11, revision.length() - 2) + ")";
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 <        return friendlyName + "{"+ className + "}(" + revision.substring(11, revision.length() - 2) + ")";
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---

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines