All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Logger.h
Go to the documentation of this file.
1 /* Copyright (C) 2001-2009 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file terralib/common/Logger.h
22 
23  \brief This class is designed to manage the log of information in TerraLib.
24  */
25 
26 #ifndef __TERRALIB_COMMON_INTERNAL_LOGGER_H
27 #define __TERRALIB_COMMON_INTERNAL_LOGGER_H
28 
29 // TerraLib
30 #include "Config.h"
31 #if TE_LOGGER_ENABLED
32 
33 // TerraLib
34 #include "Enums.h"
35 #include "Static.h"
36 
37 // STL
38 #include <string>
39 
40 namespace te
41 {
42  namespace common
43  {
44  /*!
45  \class Logger
46 
47  \brief This class is designed to manage the log of information in TerraLib.
48 
49  You just need to register the name of your logger
50  and the configuration file and type used by it.
51  When ready, you call initLogger for setting up your logger.
52 
53  All loggers name should start with "terralib." in order to be
54  in the TerraLib logger tree. So, if you have an extension called Common,
55  the name of your logger could be "terralib.common". If the name
56  was WMS, you could use "terralib.wms" and so on.
57 
58  The use of log in TerraLib doesn't need to call methods of this class,
59  instead just use the macros to report to the log. It will allow you to turn the log off
60  when desired.
61 
62  Don't worry! Logging is used in TerraLib with so much care...
63  only in special places, in order to not slowdown its
64  performance. So we don't have any performance problem/penality by using a log.
65  And if you want, you can disable the logger so that no code is put into
66  the executable, see TE_LOGGER_ENABLED.
67 
68  \note The methods provided by this class must be used only after all static data has been initialized.
69 
70  \ingroup common
71  */
72  class TECOMMONEXPORT Logger : public Static
73  {
74  public:
75 
76  /** @name Configuration Methods
77  * Methods used to configure, initialize and finalize the logger.
78  */
79  //@{
80 
81  /*!
82  \brief It returns the default configuration file name with full path.
83 
84  If none is set this method will search for a file defined in the macro TE_LOGGER_DEFAULT_CONFIGURATION_FILE (conf/te-log.conf):
85  <ul>
86  <li>under application default dir</li>
87  <li>then in the dir specified by the TERRALIB_DIR_ENVIRONMENT_VARIABLE</li>
88  </ul>
89 
90  If no file is found they return an empty string.
91 
92  \return The default configuration file name with full path or an empty string if none is found.
93  */
94  static std::string getDefaultConfigFile();
95 
96  /*!
97  \brief It initializes a given logger based on its configuration properties.
98 
99  By default, if you not specify a logger configuration file, your new logger
100  will share the same configuration as the TerraLib tree of loggers.
101 
102  \param loggerName The fully qualified logger name. Example: terralib.common.
103  \param t The type of configuration to be used by the logger.
104  \param fileName If logger configuration is file based (text or XML), the file name (with its full path or the relative path to the TerraLib current directory).
105 
106  \exception Exception It raises an exception if the fileName is missing for a file based configuraton logger.
107  */
108  static void initialize(const std::string& loggerName,
109  const LoggerConfigurationType t,
110  const std::string& fileName);
111 
112  /*!
113  \brief It initializes a given logger based on its parent configuration.
114 
115  \param loggerName The fully qualified logger name. Example: terralib.common.
116 
117  \exception Exception It raises an exception if the fileName is missing.
118  */
119  static void initialize(const std::string& loggerName);
120 
121  /*!
122  \brief It removes the appenders and other stuffs from the logger and then eliminates them from the system.
123 
124  \param loggerName The fully qualified logger name. Example: terralib.common.
125  */
126  static void finalize(const std::string& loggerName);
127 
128  //@}
129 
130  /** @name Logging Methods
131  * Methods that can be used to send messages to the log. Please, see the logger macros defined in Config.h.
132  * There are a set of macros that can me used instead of using the methods of this class that can
133  * make things easier when disabling the logger support.
134  */
135  //@{
136 
137  /*!
138  \brief Use this class method in order to log a message to a specified logger with the FATAL level.
139 
140  \param logger The name of a logger. Example: "te.common".
141  \param msg The message to be logged. Example: "Exception raised because of a missing parameter!".
142 
143  \note The FATAL level designates very severe error events that will presumably lead the application to abort.
144 
145  \note Avoid using this method. Try to use the macro TE_LOG_FATAL or TE_TASK_LOG_FATAL.
146  */
147  static void logFatal(const char* logger, const char* msg);
148 
149  /*!
150  \brief Use this class method in order to log a message to a specified logger with the FATAL level.
151 
152  \param logger The name of a logger. Example: "te.common".
153  \param msg The message to be logged. Example: "Exception raised because of a missing parameter!".
154 
155  \note The FATAL level designates very severe error events that will presumably lead the application to abort.
156 
157  \note Avoid using this method. Try to use the macro TE_LOG_FATAL or TE_TASK_LOG_FATAL.
158  */
159  static void logFatal(const std::string& logger, const std::string& msg);
160 
161  /*!
162  \brief Use this class method in order to log a message to a specified logger with the ASSERT level.
163 
164  \param logger The name of a logger. Example: "te.common".
165  \param condition An expression (condition). If it is not true, the message will be logged.
166  \param msg The message to be logged. Example: "Exception raised because of a missing parameter!".
167 
168  \note The ASSERT level can be used to check expressions that must be evaluated as true.
169 
170  \note Avoid using this method. Try to use the macro TE_LOG_ASSERT or TE_TASK_LOG_ASSERT.
171  */
172  static void logAssert(const char* logger, bool condition, const char* msg);
173 
174  /*!
175  \brief Use this class method in order to log a message to a specified logger with the ERROR level.
176 
177  \param logger The name of a logger. Example: "te.common".
178  \param msg The message to be logged. Example: "Exception raised because of a missing parameter!".
179 
180  \note The ERROR level designates error events that might still allow the application to continue running.
181 
182  \note Avoid using this method. Try to use the macro TE_LOG_ERROR or TE_TASK_LOG_ERROR.
183  */
184  static void logError(const char* logger, const char* msg);
185 
186  /*!
187  \brief Use this class method in order to log a message to a specified logger with the WARNING level.
188 
189  \param logger The name of a logger. Example: "te.common".
190  \param msg The message to be logged. Example: "Exception raised because of a missing parameter!".
191 
192  \note The WARNING level designates potentially harmful situations.
193 
194  \note Avoid using this method. Try to use the macro TE_LOG_WARNING or TE_TASK_LOG_WARNING.
195  */
196  static void logWarning(const char* logger, const char* msg);
197 
198  /*!
199  \brief Use this class method in order to log a message to a specified logger with the INFO level.
200 
201  \param logger The name of a logger. Example: "te.common".
202  \param msg The message to be logged. Example: "Exception raised because of missing parameter!".
203 
204  \note The INFO level designates informational messages that highlight the progress of the application at coarse-grained level.
205 
206  \note Avoid using this method. Try to use the macro TE_LOG_INFO or TE_TASK_LOG_INFO.
207  */
208  static void logInfo(const char* logger, const char* msg);
209 
210  /*!
211  \brief Use this class method in order to log a message to a specified logger with the INFO level.
212 
213  \param logger The name of a logger. Example: "te.common".
214  \param msg The message to be logged. Example: "Exception raised because of missing parameter!".
215 
216  \note The INFO level designates informational messages that highlight the progress of the application at coarse-grained level.
217 
218  \note Avoid using this method. Try to use the macro TE_LOG_INFO or TE_TASK_LOG_INFO.
219  */
220  static void logInfo(const std::string& logger, const std::string& msg);
221 
222  /*!
223  \brief Use this clas smethod in order to log a message to a specified logger with the DEBUG level.
224 
225  \param logger The name of a logger. Example: "te.common".
226  \param msg The message to be logged. Example: "Exception raised because of missing parameter!".
227 
228  \note The DEBUG Level designates fine-grained informational events that are most useful to debug an application.
229 
230  \note Avoid using this method. Try to use the macro TE_LOG_DEBUG or TE_TASK_LOG_DEBUG.
231  */
232  static void logDebug(const char* logger, const char* msg);
233 
234  /*!
235  \brief Use this class method in order to log a message to a specified logger with the TRACE level.
236 
237  \param logger The name of a logger. Example: "terralib".
238  \param msg The message to be logged. Example: "Exception raised because of missing parameter!".
239 
240  \note The TRACE Level designates finer-grained informational events than the DEBUG.
241 
242  \note Avoid using this method. Try to use the macro TE_LOG_TRACE or TE_TASK_LOG_TRACE.
243  */
244  static void logTrace(const char* logger, const char* msg);
245 
246  /*!
247  \brief Use this class method in order to log a message to a specified logger with the TRACE level.
248 
249  \param logger The name of a logger. Example: "terralib".
250  \param msg The message to be logged. Example: "Exception raised because of missing parameter!".
251 
252  \note The TRACE Level designates finer-grained informational events than the DEBUG.
253 
254  \note Avoid using this method. Try to use the macro TE_LOG_TRACE or TE_TASK_LOG_TRACE.
255  */
256  static void logTrace(const std::string& logger, const std::string& msg);
257 
258  //@}
259 
260  private:
261 
262  /** @name Instantiation of Objects
263  * Instantiation of objects don't allowed.
264  */
265  //@{
266 
267  /*! \brief As all private constructor, it doesn't allow direct instantiation of a Logger. */
268  //Logger();
269 
270  //@}
271  };
272 
273  } // end namespace common
274 } // end namespace te
275 
276 #endif // TE_LOGGER_ENABLED
277 
278 #endif // __TERRALIB_COMMON_INTERNAL_LOGGER_H
279 
LoggerConfigurationType
Each enumerated type tells TerraLib how the configuration is done for a logger.
Definition: Enums.h:65
#define TECOMMONEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:455
A base type for static classes.
Configuration flags for the TerraLib Common Runtime module.