View Javadoc

1   /*
2    * This file is part of Domingo
3    * an Open Source Java-API to Lotus Notes/Domino
4    * hosted at http://domingo.sourceforge.net
5    *
6    * Copyright (c) 2003-2006 Beck et al. projects GmbH München (http://www.bea.de)
7    *
8    * This library is free software; you can redistribute it and/or
9    * modify it under the terms of the GNU Lesser General Public
10   * License as published by the Free Software Foundation; either
11   * version 2.1 of the License, or (at your option) any later version.
12   *
13   * This library is distributed in the hope that it will be useful,
14   * but WITHOUT ANY WARRANTY; without even the implied warranty of
15   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16   * Lesser General Public License for more details.
17   *
18   * You should have received a copy of the GNU Lesser General Public
19   * License along with this library; if not, write to the Free Software
20   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21   */
22  
23  package de.bea.domingo.connector.impl;
24  
25  import java.io.PrintWriter;
26  import java.text.SimpleDateFormat;
27  import java.util.Date;
28  
29  import de.bea.domingo.DNotesMonitor;
30  import de.bea.domingo.monitor.AbstractDefaultMonitor;
31  
32  /***
33   * @author <a href=mailto:kurt.riede@bea.de>Kurt Riede</a>
34   */
35  public final class DomingoLogAdapter extends AbstractDefaultMonitor implements DNotesMonitor {
36  
37      private PrintWriter writer;
38  
39      /*** Date format used to format dates in log output. */
40      private final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss");
41  
42      /***
43       * Constructor.
44       */
45      public DomingoLogAdapter() {
46          super();
47      }
48  
49      /***
50       * Constructor.
51       *
52       * @param theLevel the log level
53       */
54      public DomingoLogAdapter(final int theLevel) {
55          super(theLevel);
56      }
57  
58      /***
59       * Sets a new writer to be used by this monitor.
60       *
61       * @param theWriter the new print writer
62       */
63      public void setWriter(final PrintWriter theWriter) {
64          writer = theWriter;
65      }
66  
67      /***
68       * Returns the current writer of the monitor.
69       *
70       * @return the current writer
71       */
72      public PrintWriter getWriter() {
73          return writer;
74      }
75  
76      /***
77       * {@inheritDoc}
78       *
79       * @see de.bea.domingo.monitor.AbstractDefaultMonitor#monitor(java.lang.String)
80       */
81      protected void monitor(final String message) {
82          final StringBuffer buffer = new StringBuffer();
83          buffer.append("[" + dateFormat.format(new Date()) + "] ");
84          buffer.append(Thread.currentThread().getName() + ": " + message);
85          writer.println(buffer.toString());
86          writer.flush();
87      }
88  
89      /***
90       * {@inheritDoc}
91       *
92       * @see de.bea.domingo.monitor.AbstractDefaultMonitor#monitor(java.lang.Throwable)
93       */
94      protected void monitor(final Throwable throwable) {
95          if (throwable != null) {
96              throwable.printStackTrace(writer);
97          }
98      }
99  }