bump product version to 4.1.6.2
[LibreOffice.git] / qadevOOo / runner / stats / FileLogWriter.java
blob953814f16687f7edb454c6b433f8ad0b9efe63c9
1 /*
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 .
19 package stats;
21 import java.io.FileWriter;
22 import java.io.IOException;
23 import share.LogWriter;
25 import java.io.PrintWriter;
26 import java.text.DecimalFormat;
27 import java.util.Calendar;
28 import java.util.GregorianCalendar;
29 import java.util.HashMap;
30 import java.util.Iterator;
32 public class FileLogWriter extends PrintWriter implements LogWriter {
35 HashMap<String, FileWriter> mFileWriters = null;
36 boolean logging = false;
37 share.DescEntry entry = null;
38 share.Watcher ow = null;
40 public FileLogWriter() {
41 super(System.out);
42 Calendar cal = new GregorianCalendar();
43 DecimalFormat dfmt = new DecimalFormat("00");
44 super.println("LOG> Log started " +
45 dfmt.format(cal.get(Calendar.DAY_OF_MONTH)) + "." +
46 dfmt.format(cal.get(Calendar.MONTH)) + "." +
47 dfmt.format(cal.get(Calendar.YEAR)) + " - " +
48 dfmt.format(cal.get(Calendar.HOUR_OF_DAY)) + ":" +
49 dfmt.format(cal.get(Calendar.MINUTE)) + ":" +
50 dfmt.format(cal.get(Calendar.SECOND)));
51 super.flush();
54 public boolean initialize(share.DescEntry entry, boolean logging) {
55 this.logging = logging;
56 this.entry = entry;
57 return true;
61 public void addFileLog(String filePath){
62 try{
63 if(mFileWriters == null)
64 mFileWriters = new HashMap<String, FileWriter>();
65 mFileWriters.put(filePath, new FileWriter(filePath));
66 }catch(IOException e ){
67 e.printStackTrace(this);
72 public void removeFileLog(String filePath){
73 if(filePath != null)
74 mFileWriters.remove(filePath);
78 public void println(String msg) {
80 this.ow = (share.Watcher) entry.UserDefinedParams.get("Watcher");
82 if (ow != null) {
83 ow.ping();
85 if (logging) {
87 // logoutput to console
88 super.println("LOG> "+msg);
89 super.flush();
91 //logoutput to file
92 if(mFileWriters != null && mFileWriters.size() > 0){
93 try{
94 FileWriter fw = null;
95 Iterator<FileWriter> iter = mFileWriters.values().iterator();
96 while(iter.hasNext()){
97 fw = iter.next();
98 fw.write("LOG> " + msg + "\n");
99 fw.flush();
101 }catch(IOException e ){
102 e.printStackTrace(this);
108 public boolean summary(share.DescEntry entry) {
109 String header = "***** State for "+entry.longName+" ******";
110 System.out.println(header);
111 if (entry.hasErrorMsg) {
112 System.out.println(entry.ErrorMsg);
113 System.out.println("Whole "+entry.EntryType+": "+entry.State);
114 } else {
115 System.out.println("Whole "+entry.EntryType+": "+entry.State);
117 for (int i=0;i<header.length();i++) {
118 System.out.print("*");
120 System.out.println("");
121 return true;
124 public Object getWatcher() {
125 return this.ow;
128 public void setWatcher(Object watcher) {
129 entry.UserDefinedParams.put("Watcher", watcher);