Source code: org/javahispano/canyamo/core/CanyamoLog.java
1 /*
2 Caņamo, portal framework
3 Copyright (c) 2002
4 Alberto Molpeceres, javaHispano (http://www.javahispano.org)
5 All rights reserved.
6 .
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9 Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer.
11 Redistributions in binary form must reproduce the above copyright notice,
12 this list of conditions and the following disclaimer in the documentation
13 and/or other materials provided with the distribution.
14 Neither the name of Alberto Molpeceres, javaHispano nor the names of its
15 contributors may be used to endorse or promote products derived from
16 this software without specific prior written permission.
17 .
18 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
22 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
23 OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
26 IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
28 THE POSSIBILITY OF SUCH DAMAGE.
29 */
30 package org.javahispano.canyamo.core;
31
32 import javax.servlet.http.*;
33 import javax.servlet.*;
34
35 /**
36 * Static class that acts as log system for Canyamo.<br>
37 * <br>
38 * Based in ServletContext's log to write in AppServer's log.
39 *
40 *@author <a href="mailto:al AT javahispano DOT org">Alberto Molpeceres</a>
41 *@created 28. August 2002
42 *@version
43 *@since
44 */
45 public final class CanyamoLog {
46
47 /** Determines if debug sentences are logged or not */
48 private final static boolean DEBUG = true;
49
50 /** Canyamo Servlet's context. Used to get app. server's log file */
51 private static ServletContext context;
52
53
54 /**
55 * Initialites log system
56 *
57 *@param c CanyamoServlet's context
58 */
59 public static void init(ServletContext c) {
60 context = c;
61 }
62
63
64 /**
65 * Logs a message
66 *
67 *@param message Test to log
68 */
69 public static void log(String message) {
70 context.log(message);
71 }
72
73
74 /**
75 * Logs a message
76 *
77 *@param message Description of Parameter
78 *@param object Description of Parameter
79 */
80 public static void log(String message, String object) {
81 context.log(message + ": " + object);
82 }
83
84
85 /**
86 * Logs a message with debug flag
87 *
88 *@param message Test to log
89 */
90 public static void debug(String message) {
91 if (DEBUG) {
92 log("[DEBUG] " + message);
93 }
94 }
95
96
97 /**
98 * Logs a message with debug flag
99 *
100 *@param message Description of Parameter
101 *@param object Description of Parameter
102 */
103 public static void debug(String message, String object) {
104 if (DEBUG) {
105 log("[DEBUG] " + message, object);
106 }
107 }
108
109
110 /**
111 * Logs a message with error flag
112 *
113 *@param message Test to log
114 */
115 public static void error(String message) {
116 log("[ERROR] " + message);
117 }
118
119
120 /**
121 * Logs a message with error flag
122 *
123 *@param message Description of Parameter
124 *@param object Description of Parameter
125 */
126 public static void error(String message, String object) {
127 log("[ERROR] " + message, object);
128 }
129
130 }
131