ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/experimental/server/Logger/ScreenLog.java
Revision: 1.1
Committed: Mon Nov 6 21:28:47 2000 UTC (24 years, 1 month ago) by tdb
Branch: MAIN
CVS Tags: PROJECT_COMPLETION, HEAD
Error occurred while calculating annotation data.
Log Message:
Screen Logging implementation of the logging mechanism interface.

File Contents

# Content
1 import java.util.Date;
2 import java.text.DateFormat;
3 import java.util.Locale;
4
5 /**
6 * ScreenLog <br> <br>
7 *
8 * The ScreenLog class is an implementation of the Log interface. It's
9 * purpose is to write output to the screen. All it really does is
10 * format the input line of text and print it out. <br> <br>
11 *
12 * Revision History: <br>
13 * 1.2 - Tidied javadoc comments [26/04/00] <br>
14 * 1.1 - Used an interface to create seperate File & Screen logs [15/03/00] <br>
15 * 1.0 - Original File-only version <br>
16 *
17 * @author T.D.Bishop [tdb1@ukc.ac.uk]
18 * @version 1.2, 25/04/2000
19 */
20 public class ScreenLog implements Log {
21
22 /**
23 * This attribute is used by the Server class to print out versions
24 * of all class files that form the server on startup.
25 */
26 public static String version = "1.2, 25/04/2000";
27
28 /**
29 * The default no-arg constructor simply prints a message to the
30 * screen stating that logging has started, then leaves the object
31 * awaiting further messages.
32 */
33 public ScreenLog(){
34 write(this, "Logging initialised");
35 }
36
37 /**
38 * The write() method takes a message, formats it using the
39 * formatLogLine() method, and then outputs it to the screen
40 * using System.out.println(). The source is usually the
41 * calling object, referenced by `this'.
42 *
43 * @param source A reference to the calling object.
44 * @param input The text to be logged.
45 */
46 public void write(Object source, String input){
47 String line = formatLogLine(source, input);
48 System.out.println(line);
49 }
50
51 /**
52 * This method generates a nicely formatted line for the log,
53 * including the date/time and the source of the message. The date
54 * and time are formatted using the DateFormat class, and the source
55 * class is formatted using the toString() method found in every
56 * source file for the server. This is then prepended to the message
57 * and returned.
58 *
59 * @param source A reference to the source of the message.
60 * @param input The message to be logged.
61 * @return The string to be written to the log.
62 */
63 private String formatLogLine(Object source, String input){
64 String date = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM).format(new Date());
65 return "[" + date + "] " + source.toString() + ": " + input;
66 }
67
68 /**
69 * The toString() method returns the name of the Class for formatting
70 * when it writes to the logfile. <br>
71 *
72 * @return The formatted string identifying this Class.
73 */
74 public String toString(){
75 return this.getClass().getName();
76 }
77
78 /**
79 * The close() method closes the logging, although in this
80 * case there isn't anything to close.
81 */
82 public void close(){
83 write(this, "Attempting to terminate logging");
84 }
85
86 /**
87 * This method hasn't been implemented due to the complexity
88 * of clearing a screen in Java. A message is printed notifying
89 * the user of this event.
90 */
91 public void clear(){
92 write(this, "Clear() not implemented in ScreenLog");
93 }
94
95 }