source: main/trunk/gli/src/org/greenstone/gatherer/DebugStream.java@ 36272

Last change on this file since 36272 was 34261, checked in by ak19, 4 years ago
  1. Fixed the bug with GLI's Gather Rightclick > Replace when the replacement file and the file being replaced had the same name. Things mostly worked, including in the remote case: when the filenames were the same or different, the files would get correctly transferred, retaining meta, to the remote GS. But if the files were the same name, then in (client)GLI the file ends up lost unless it's client-GLI, in which case reopening the collection transferred the correct new file across with meta. This bugfix ensures that nothing is lost in GLI or client-GLI and that no reopening of client-GLI is necessary to fix it. The final fix ended up far easier than all my initial ways of solving it which failed to work (like renaming the src file temporarily while copying the identically named target across). 2. DebugStream error msg visibility can now be toggled on and off and prints START DEBUGGING to END DEBUGGING messages with caller name for the section of code where it's toggled on. This came in handy when debugging this time, so leaving it in for future use.
  • Property svn:keywords set to Author Date Id Revision
File size: 3.3 KB
Line 
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
27package org.greenstone.gatherer;
28
29
30import java.io.*;
31import java.util.*;
32
33
34public 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 void setDebugging(boolean isEnabled, String caller) {
61 if(isEnabled) {
62 System.err.println("**** START DEBUGGING (enabled by: " + caller + ")");
63 } else {
64 System.err.println("**** END DEBUGGING (called by: " + caller + ")");
65 }
66 debugging_enabled = isEnabled;
67 }
68
69 static synchronized public boolean isDebuggingEnabled()
70 {
71 return debugging_enabled;
72 }
73
74
75 static synchronized public void print(Properties properties)
76 {
77 if (debugging_enabled) {
78 if (debug_stream != null) {
79 properties.list(debug_stream);
80 }
81 properties.list(System.err);
82 }
83 }
84
85
86 /** Print a message to the debug stream. */
87 static synchronized public void print(String message)
88 {
89 if (debugging_enabled) {
90 if (debug_stream != null) {
91 debug_stream.print(message);
92 }
93 System.err.print(message);
94 }
95 }
96
97
98 /** Print a message to the debug stream. */
99 static synchronized public void println(String message)
100 {
101 if (debugging_enabled) {
102 if (debug_stream != null) {
103 debug_stream.println(message);
104 }
105 System.err.println(message);
106 }
107 }
108
109
110 /** Print a stack trace to the debug stream, and always to STDERR. */
111 static synchronized public void printStackTrace(Exception exception)
112 {
113 if (debugging_enabled && debug_stream != null) {
114 exception.printStackTrace(debug_stream);
115 }
116 exception.printStackTrace();
117 }
118
119
120 static public void setDebugFile(String debug_file_path)
121 {
122 try {
123 debug_stream = new PrintStream(new FileOutputStream(debug_file_path));
124 }
125 catch (Exception exception) {
126 exception.printStackTrace();
127 }
128 }
129}
Note: See TracBrowser for help on using the repository browser.