1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 package com.sun.star.filter.config.tools.utils;
25 
26 //_______________________________________________
27 // imports
28 
29 import java.lang.*;
30 import java.util.*;
31 
32 //_______________________________________________
33 // definition
34 
35 /** can be used to print out some debug messages
36  *  and group it into warnings/errors or info statements.
37  *
38  *
39  */
40 public class Logger
41 {
42     //___________________________________________
43     // const
44 
45     /** only error message will be shown. */
46     public static final int LEVEL_ERRORS = 1;
47 
48     /** only errors and warnings will be shown. */
49     public static final int LEVEL_WARNINGS = 2;
50 
51     /** enable errors/warnings and some global info
52      *  message. */
53     public static final int LEVEL_GLOBALINFOS = 3;
54 
55     /** enable anything! */
56     public static final int LEVEL_DETAILEDINFOS = 4;
57 
58     //___________________________________________
59     // member
60 
61     /** enable/disable different output level.
62      *  e.g. warnings/errors/infos */
63     private int m_nLevel;
64 
65     //___________________________________________
66     // ctor
67 
68     /** initialize new debug object with the specified
69      *  debug level.
70      *
71      *  @param  nLevel
72      *          the new debug level.
73      *          See const values LEVEL_xxx too.
74      */
Logger(int nLevel)75     public Logger(int nLevel)
76     {
77         m_nLevel = nLevel;
78     }
79 
80     //___________________________________________
81     // interface
82 
83     /** initialize new debug object with a default
84      *  debug level.
85      */
Logger()86     public Logger()
87     {
88         m_nLevel = LEVEL_DETAILEDINFOS;
89     }
90 
91     //___________________________________________
92     // interface
93 
94     /** prints out an exception ... if the right level is set.
95      *
96      *  @param  ex
97      *          the exception object
98      */
setException(java.lang.Throwable ex)99     public synchronized void setException(java.lang.Throwable ex)
100     {
101         if (m_nLevel >= LEVEL_ERRORS)
102         {
103             System.err.println("Exception:\n");
104             ex.printStackTrace();
105         }
106     }
107 
108     //___________________________________________
109     // interface
110 
111     /** prints out an error ... if the right level is set.
112      *
113      *  @param  sError
114      *          the error message.
115      */
setError(java.lang.String sError)116     public synchronized void setError(java.lang.String sError)
117     {
118         if (m_nLevel >= LEVEL_ERRORS)
119             System.err.println("Error    :\t\""+sError+"\"");
120     }
121 
122     //___________________________________________
123     // interface
124 
125     /** prints out a warning ... if the right level is set.
126      *
127      *  @param  sWarning
128      *          the warning message.
129      */
setWarning(java.lang.String sWarning)130     public synchronized void setWarning(java.lang.String sWarning)
131     {
132         if (m_nLevel >= LEVEL_WARNINGS)
133             System.err.println("Warning  :\t\""+sWarning+"\"");
134     }
135 
136     //___________________________________________
137     // interface
138 
139     /** prints out a global info message ... if the right level is set.
140      *
141      *  Global infos should be used to describe a complex operation.
142      *  E.g.: loading of a document.
143      *  But not for every sub operation like e.g. analyzing lines
144      *  during loading the document!
145      *
146      *  @param  sInfo
147      *          the info message.
148      */
setGlobalInfo(java.lang.String sInfo)149     public synchronized void setGlobalInfo(java.lang.String sInfo)
150     {
151         if (m_nLevel >= LEVEL_GLOBALINFOS)
152             System.out.println("Info     :\t\""+sInfo+"\"");
153     }
154 
155     //___________________________________________
156     // interface
157 
158     /** prints out a mode detailed info message ... if the right level is set.
159      *
160      *  Such detailed message are e.g. "analyze line [n] of file ...".
161      *
162      *  @param  sInfo
163      *          the info message.
164      */
setDetailedInfo(java.lang.String sInfo)165     public synchronized void setDetailedInfo(java.lang.String sInfo)
166     {
167         if (m_nLevel >= LEVEL_DETAILEDINFOS)
168             System.out.println("Detail   :\t\""+sInfo+"\"");
169     }
170 }
171