[8234] | 1 | /**
|
---|
| 2 | *############################################################################
|
---|
| 3 | * A component of the Greenstone Librarian Interface, part of the Greenstone
|
---|
| 4 | * digital library suite from the New Zealand Digital Library Project at the
|
---|
| 5 | * University of Waikato, New Zealand.
|
---|
| 6 | *
|
---|
| 7 | * Author: Michael Dewsnip, NZDL Project, University of Waikato, NZ
|
---|
| 8 | *
|
---|
| 9 | * Copyright (C) 2004 New Zealand Digital Library Project
|
---|
| 10 | *
|
---|
| 11 | * This program is free software; you can redistribute it and/or modify
|
---|
| 12 | * it under the terms of the GNU General Public License as published by
|
---|
| 13 | * the Free Software Foundation; either version 2 of the License, or
|
---|
| 14 | * (at your option) any later version.
|
---|
| 15 | *
|
---|
| 16 | * This program is distributed in the hope that it will be useful,
|
---|
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 19 | * GNU General Public License for more details.
|
---|
| 20 | *
|
---|
| 21 | * You should have received a copy of the GNU General Public License
|
---|
| 22 | * along with this program; if not, write to the Free Software
|
---|
| 23 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
| 24 | *############################################################################
|
---|
| 25 | */
|
---|
| 26 |
|
---|
| 27 | package org.greenstone.gatherer;
|
---|
| 28 |
|
---|
| 29 |
|
---|
| 30 | import java.io.*;
|
---|
| 31 | import java.util.*;
|
---|
| 32 |
|
---|
| 33 |
|
---|
| 34 | public class DebugStream
|
---|
| 35 | {
|
---|
| 36 | static private boolean debugging_enabled = false;
|
---|
| 37 | static private PrintStream debug_stream = null;
|
---|
| 38 |
|
---|
| 39 |
|
---|
| 40 | static public void closeDebugStream()
|
---|
| 41 | {
|
---|
| 42 | if (debug_stream != null) {
|
---|
| 43 | try {
|
---|
| 44 | debug_stream.flush();
|
---|
| 45 | debug_stream.close();
|
---|
| 46 | }
|
---|
| 47 | catch (Exception exception) {
|
---|
| 48 | exception.printStackTrace();
|
---|
| 49 | }
|
---|
| 50 | }
|
---|
| 51 | }
|
---|
| 52 |
|
---|
| 53 |
|
---|
| 54 | static public void enableDebugging()
|
---|
| 55 | {
|
---|
| 56 | debugging_enabled = true;
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 |
|
---|
| 60 | static public boolean isDebuggingEnabled()
|
---|
| 61 | {
|
---|
| 62 | return debugging_enabled;
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 |
|
---|
| 66 | static synchronized public void print(Properties properties)
|
---|
| 67 | {
|
---|
| 68 | if (debugging_enabled) {
|
---|
| 69 | if (debug_stream != null) {
|
---|
| 70 | properties.list(debug_stream);
|
---|
| 71 | }
|
---|
| 72 | properties.list(System.err);
|
---|
| 73 | }
|
---|
| 74 | }
|
---|
| 75 |
|
---|
| 76 |
|
---|
| 77 | /** Print a message to the debug stream. */
|
---|
| 78 | static synchronized public void print(String message)
|
---|
| 79 | {
|
---|
| 80 | if (debugging_enabled) {
|
---|
| 81 | if (debug_stream != null) {
|
---|
| 82 | debug_stream.print(message);
|
---|
| 83 | }
|
---|
| 84 | System.err.print(message);
|
---|
| 85 | }
|
---|
| 86 | }
|
---|
| 87 |
|
---|
| 88 |
|
---|
| 89 | /** Print a message to the debug stream. */
|
---|
| 90 | static synchronized public void println(String message)
|
---|
| 91 | {
|
---|
| 92 | if (debugging_enabled) {
|
---|
| 93 | if (debug_stream != null) {
|
---|
| 94 | debug_stream.println(message);
|
---|
| 95 | }
|
---|
| 96 | System.err.println(message);
|
---|
| 97 | }
|
---|
| 98 | }
|
---|
| 99 |
|
---|
| 100 |
|
---|
[12651] | 101 | /** Print a stack trace to the debug stream, and always to STDERR. */
|
---|
[8234] | 102 | static synchronized public void printStackTrace(Exception exception)
|
---|
| 103 | {
|
---|
| 104 | if (debugging_enabled && debug_stream != null) {
|
---|
| 105 | exception.printStackTrace(debug_stream);
|
---|
| 106 | }
|
---|
| 107 | exception.printStackTrace();
|
---|
| 108 | }
|
---|
| 109 |
|
---|
| 110 |
|
---|
| 111 | static public void setDebugFile(String debug_file_path)
|
---|
| 112 | {
|
---|
| 113 | try {
|
---|
| 114 | debug_stream = new PrintStream(new FileOutputStream(debug_file_path));
|
---|
| 115 | }
|
---|
| 116 | catch (Exception exception) {
|
---|
| 117 | exception.printStackTrace();
|
---|
| 118 | }
|
---|
| 119 | }
|
---|
| 120 | }
|
---|