LibreOffice Module xmerge (master) 1
Debug.java
Go to the documentation of this file.
1/*
2 * This file is part of the LibreOffice project.
3 *
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 *
8 * This file incorporates work covered by the following license notice:
9 *
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
17 */
18
19package org.openoffice.xmerge.util;
20
21import java.io.BufferedWriter;
22import java.io.IOException;
23import java.io.FileWriter;
24import java.io.InputStream;
25import java.io.OutputStream;
26import java.io.OutputStreamWriter;
27import java.io.PrintWriter;
28import java.io.Writer;
29import java.util.Properties;
30
39public final class Debug {
40
42 public static final int INFO = 0x0001;
44 public static final int ERROR = 0x0002;
46 public static final int TRACE = 0x0004;
47
49 private static final boolean SET = true;
50
51 private static int flags = 0;
52 private static PrintWriter writer = null;
53
54 static {
55
56 InputStream is = null;
57 try {
58 try {
59 is = Debug.class.getResourceAsStream("Debug.properties");
61 props.load(is);
62
63 String info = props.getProperty("debug.info", "false");
64 info = info.toLowerCase();
65
66 if (info.equals("true")) {
68 }
69
70 String trace = props.getProperty("debug.trace", "false");
71 trace = trace.toLowerCase();
72
73 if (trace.equals("true")) {
75 }
76
77 String error = props.getProperty("debug.error", "false");
78 error = error.toLowerCase();
79
80 if (error.equals("true")) {
82 }
83
84 String w = props.getProperty("debug.output", "System.out");
85 setOutput(w);
86
87 } finally {
88 if (is !=null)
89 is.close();
90 }
91 } catch (Throwable ex) {
92 ex.printStackTrace(System.err);
93 }
94 }
95
101 private Debug() {
102 }
103
112 private static void setOutput(String str) {
113 if (writer == null) {
114 if (str.equals("System.out")) {
115 setOutput(System.out);
116 } else if (str.equals("System.err")) {
117 setOutput(System.err);
118 } else {
119 try {
120 setOutput(new FileWriter(str));
121 } catch (IOException e) {
122 e.printStackTrace(System.err);
123 }
124 }
125 }
126 }
127
133 private static void setOutput(OutputStream stream) {
134 setOutput(new OutputStreamWriter(stream));
135 }
136
142 private static void setOutput(Writer w) {
143 if (writer != null) {
144 writer.close();
145 }
146 writer = new PrintWriter(new BufferedWriter(w), true);
147 }
148
163 private static void setFlags(int f, boolean set) {
164 if (set) {
165 flags |= f;
166 } else {
167 flags &= ~f;
168 }
169 }
170
176 public static boolean isFlagSet(int f) {
177 return ((flags & f) != 0);
178 }
179
205 public static void log(int flag, String msg) {
206 if (isFlagSet(flag) && writer != null) {
207 writer.println(msg);
208 }
209 }
210
223 public static void log(int flag, String msg, Throwable e) {
224 if (isFlagSet(flag) && writer != null) {
225 writer.println(msg);
226 if (e != null)
227 e.printStackTrace(writer);
228 }
229 }
230}
This class is used for logging debug messages.
Definition: Debug.java:39
static final int INFO
Informational messages.
Definition: Debug.java:42
static PrintWriter writer
Definition: Debug.java:52
static final boolean SET
To set a flag.
Definition: Debug.java:49
static void setOutput(Writer w)
Set the Writer object to manage the output.
Definition: Debug.java:142
static boolean isFlagSet(int f)
Checks if flag is set.
Definition: Debug.java:176
static final int TRACE
Trace messages.
Definition: Debug.java:46
Debug()
Private constructor so as not to allow any instances of this class.
Definition: Debug.java:101
static void setOutput(OutputStream stream)
Set the output to an OutputStream object.
Definition: Debug.java:133
static void setFlags(int f, boolean set)
This method sets the levels for debugging logs.
Definition: Debug.java:163
static void setOutput(String str)
Set the output to the specified argument.
Definition: Debug.java:112
static void log(int flag, String msg, Throwable e)
Log message based on flag type plus print out stack trace of the exception passed in.
Definition: Debug.java:223
static void log(int flag, String msg)
Log message based on the flag type.
Definition: Debug.java:205
static final int ERROR
Error messages.
Definition: Debug.java:44
Reference< XOutputStream > stream
dictionary props
sal_Int32 w