01: /*
02: * Copyright 2001 Sun Microsystems, Inc. All rights reserved.
03: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
04: */
05:
06: package com.sun.portal.search.admin;
07:
08: import java.io.*;
09: import java.util.Date;
10: import java.text.*;
11:
12: public class CSDebug {
13: protected static PrintWriter out = null;
14: static DateFormat df = new SimpleDateFormat("dd/MMM/yyyy:HH:mm:ss");
15:
16: static boolean enabled = false;
17:
18: static void init() {
19: String server_root = CSConfig.getServerRoot();
20: if (server_root == null) {
21: server_root = ".";
22: }
23: String debug_file = "debug.log";
24: try {
25: FileOutputStream fout = new FileOutputStream(server_root
26: + File.separator + debug_file, true);
27: out = new PrintWriter(new BufferedWriter(
28: new OutputStreamWriter(fout, "UTF-8")), true);
29: enabled = true;
30: } catch (Exception e) {
31: }
32:
33: }
34:
35: public static void log(String msg) {
36: if (!enabled)
37: return;
38: if (out == null) {
39: init();
40: if (out == null) {
41: return;
42: }
43: }
44: out.print(msg);
45: out.flush();
46: }
47:
48: public static void setEnable(boolean set) {
49: if (set && out == null) {
50: init();
51: } else {
52: enabled = set;
53: }
54: }
55:
56: public static void logln(String msg) {
57: if (!enabled)
58: return;
59: if (out == null) {
60: init();
61: if (out == null) {
62: return;
63: }
64: }
65: out.println("[" + df.format(new Date()) + "] " + msg);
66: out.flush();
67: }
68: }
|