2 * This file is part of the LibreOffice project.
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/.
8 * This file incorporates work covered by the following license notice:
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 .
20 import java
.io
.PrintWriter
;
21 import java
.io
.StringWriter
;
24 * Write all logs into a java.io.PrintWriter, i.e. a StringBuffer.
25 * Log is gathered there.
27 public class InternalLogWriter
implements share
.LogWriter
{
29 private boolean active
;
30 /** write all output to a StringBuffer **/
31 private StringWriter writer
= new StringWriter();
32 private PrintWriter printWriter
;
37 public InternalLogWriter() {
38 printWriter
= new PrintWriter(writer
);
44 * @param entry The description entry.
45 * @param active Logging is active.
46 * @return True, if initialize worked.
48 public boolean initialize(share
.DescEntry entry
, boolean active
) {
54 * Method to print a line that is added to the StringBuffer.
55 * @param msg The message that is printed.
57 public void println(String msg
) {
59 printWriter
.println(msg
);
63 * Is used to sum up the information.
64 * The summary is also added to the StringBuffer.
65 * @param entry The description entry.
66 * @return True, if a summary could be created.
68 public boolean summary(share
.DescEntry entry
) {
70 String header
= "***** State for "+entry
.longName
+" ******";
71 printWriter
.println(header
);
72 if (entry
.hasErrorMsg
) {
73 printWriter
.println(entry
.ErrorMsg
);
74 printWriter
.println("Whole "+entry
.EntryType
+": "+entry
.State
);
76 printWriter
.println("Whole "+entry
.EntryType
+": "+entry
.State
);
78 for (int i
=0;i
<header
.length();i
++) {
79 printWriter
.print("*");
81 printWriter
.println("");
86 * Return all the written stuff.
87 * @return All that was written to the StringBuffer with the
88 * 'println()', 'print()' and 'summarize()' methods.
89 * The StringBuffer is emptied afterwards.
91 public String
getLog() {
92 String message
= writer
.getBuffer().toString();
93 writer
= new StringWriter();
97 public void setWatcher(Object watcher
) {