1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: FileLogWriter.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
33 import java
.io
.FileWriter
;
34 import java
.io
.IOException
;
35 import share
.LogWriter
;
37 import java
.io
.PrintWriter
;
38 import java
.text
.DecimalFormat
;
39 import java
.util
.Calendar
;
40 import java
.util
.GregorianCalendar
;
41 import java
.util
.HashMap
;
42 import java
.util
.Iterator
;
44 public class FileLogWriter
extends PrintWriter
implements LogWriter
{
47 HashMap mFileWriters
= null;
48 boolean logging
= false;
49 share
.DescEntry entry
= null;
50 share
.Watcher ow
= null;
52 public FileLogWriter() {
54 Calendar cal
= new GregorianCalendar();
55 DecimalFormat dfmt
= new DecimalFormat("00");
56 super.println("LOG> Log started " +
57 dfmt
.format(cal
.get(Calendar
.DAY_OF_MONTH
)) + "." +
58 dfmt
.format(cal
.get(Calendar
.MONTH
)) + "." +
59 dfmt
.format(cal
.get(Calendar
.YEAR
)) + " - " +
60 dfmt
.format(cal
.get(Calendar
.HOUR_OF_DAY
)) + ":" +
61 dfmt
.format(cal
.get(Calendar
.MINUTE
)) + ":" +
62 dfmt
.format(cal
.get(Calendar
.SECOND
)));
66 public boolean initialize(share
.DescEntry entry
, boolean logging
) {
67 this.logging
= logging
;
73 public void addFileLog(String filePath
){
75 if(mFileWriters
== null)
76 mFileWriters
= new HashMap();
77 mFileWriters
.put(filePath
, new FileWriter(filePath
));
78 }catch(IOException e
){
79 e
.printStackTrace(this);
84 public void removeFileLog(String filePath
){
86 mFileWriters
.remove(filePath
);
90 public void println(String msg
) {
92 this.ow
= (share
.Watcher
) entry
.UserDefinedParams
.get("Watcher");
99 // logoutput to console
100 super.println("LOG> "+msg
);
104 if(mFileWriters
!= null && mFileWriters
.size() > 0){
106 FileWriter fw
= null;
107 Iterator iter
= mFileWriters
.values().iterator();
108 while(iter
.hasNext()){
109 fw
= (FileWriter
) iter
.next();
110 fw
.write("LOG> " + msg
+ "\n");
113 }catch(IOException e
){
114 e
.printStackTrace(this);
120 public boolean summary(share
.DescEntry entry
) {
121 String header
= "***** State for "+entry
.longName
+" ******";
122 System
.out
.println(header
);
123 if (entry
.hasErrorMsg
) {
124 System
.out
.println(entry
.ErrorMsg
);
125 System
.out
.println("Whole "+entry
.EntryType
+": "+entry
.State
);
127 System
.out
.println("Whole "+entry
.EntryType
+": "+entry
.State
);
129 for (int i
=0;i
<header
.length();i
++) {
130 System
.out
.print("*");
132 System
.out
.println("");
136 public Object
getWatcher() {
140 public void setWatcher(Object watcher
) {
141 entry
.UserDefinedParams
.put("Watcher", (share
.Watcher
) watcher
);