TsLogger.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
3 
4  This file is part of the TerraLib - a Framework for building GIS enabled applications.
5 
6  TerraLib is free software: you can redistribute it and/or modify
7  it under the terms of the GNU Lesser General Public License as published by
8  the Free Software Foundation, either version 3 of the License,
9  or (at your option) any later version.
10 
11  TerraLib is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU Lesser General Public License for more details.
15 
16  You should have received a copy of the GNU Lesser General Public License
17  along with TerraLib. See COPYING. If not, write to
18  TerraLib Team at <terralib-team@terralib.org>.
19  */
20 
21 /*!
22  \file terralib/unittest/core/logger/TsLogger.cpp
23 
24  \brief A test suit for the TerraLib Core Logger Module.
25 
26  \author Matheus Cavassan Zaglia.
27  */
28 
29 // TerraLib
33 
34 // Boost
35 #include <boost/test/unit_test.hpp>
36 #include <boost/filesystem.hpp>
37 
38 BOOST_AUTO_TEST_SUITE(logger_test_case)
39 
40 BOOST_AUTO_TEST_CASE(default_logger_test)
41 {
43  BOOST_CHECK_NO_THROW(TE_INIT_DEFAULT_LOGGER("log/unit_test_terralib.log"));
45  BOOST_CHECK_THROW(TE_INIT_DEFAULT_LOGGER("log/unit_test_terralib.log"), te::InvalidArgumentException);
46  BOOST_CHECK_NO_THROW(TE_LOG_WARN("Warning log"));
47  BOOST_CHECK_NO_THROW(TE_LOG_INFO("Info log"));
48  BOOST_CHECK_NO_THROW(TE_LOG_ERROR("Error log"));
49  BOOST_CHECK_NO_THROW(TE_LOG_TRACE("Trace log"));
50  BOOST_CHECK_NO_THROW(TE_LOG_FATAL("Fatal log"));
51  BOOST_CHECK_NO_THROW(TE_LOG_DEBUG("Debug log"));
52  BOOST_CHECK(boost::filesystem::file_size("log/unit_test_terralib.log") > 0);
53 
54  return;
55 }
56 
57 BOOST_AUTO_TEST_CASE(configuration_file_logger_test)
58 {
59  BOOST_CHECK_THROW(TE_ADD_LOGGER_FROM_FILE("mylogger.ini"), std::exception);
60  BOOST_CHECK_NO_THROW(TE_ADD_LOGGER_FROM_FILE(
61  te::core::FindInTerraLibPath("share/terralib/config/te-log-unittest.ini")));
62  BOOST_CHECK_NO_THROW(TE_CORE_LOG_WARN("unittest","Warning log"));
63  BOOST_CHECK_NO_THROW(TE_CORE_LOG_INFO("unittest","Info log"));
64  BOOST_CHECK_NO_THROW(TE_CORE_LOG_ERROR("unittest","Error log"));
65  BOOST_CHECK_NO_THROW(TE_CORE_LOG_TRACE("unittest","Trace log"));
66  BOOST_CHECK_NO_THROW(TE_CORE_LOG_FATAL("unittest","Fatal log"));
67  BOOST_CHECK_NO_THROW(TE_CORE_LOG_DEBUG("unittest","Debug log"));
68  BOOST_CHECK(boost::filesystem::file_size(te::core::FindInTerraLibPath("log/terralib_unittest_core.log")) > 0);
69 
70  return;
71 }
72 
73 BOOST_AUTO_TEST_SUITE_END()
74 
#define TE_ADD_LOGGER_FROM_FILE(filename)
Use this tag to init a logger using a configuration file.
Definition: Logger.h:184
const std::string TERRALIB_DEFAULT_LOGGER
The default name of the log file if none is informed.
Definition: Logger.h:47
#define TE_CORE_LOG_DEBUG(channel, message)
Use this tag in order to log a message to a specified logger with the DEBUG level.
Definition: Logger.h:225
This file is a wrapper around platform specific include files.
#define TE_CORE_LOG_FATAL(channel, message)
Use this tag in order to log a message to a specified logger with the FATAL level.
Definition: Logger.h:281
BOOST_AUTO_TEST_CASE(configuration_file_logger_test)
Definition: TsLogger.cpp:57
#define TE_CORE_LOG_ERROR(channel, message)
Use this tag in order to log a message to a specified logger with the ERROR level.
Definition: Logger.h:267
#define TE_LOG_INFO(message)
Use this tag in order to log a message to the TerraLib default logger with the INFO level...
Definition: Logger.h:315
static Logger & instance()
It returns a reference to the singleton instance.
#define TE_INIT_DEFAULT_LOGGER(filename)
Use this tag in order to initialize the default TerraLib logger.
Definition: Logger.h:197
#define TE_LOG_FATAL(message)
Use this tag in order to log a message to the TerraLib default logger with the FATAL level...
Definition: Logger.h:348
This class is designed to manage the log of information in TerraLib.
BOOST_AUTO_TEST_SUITE(logger_test_case) BOOST_AUTO_TEST_CASE(default_logger_test)
Definition: TsLogger.cpp:38
#define TE_LOG_TRACE(message)
Use this tag in order to log a message to the TerraLib default logger with the TRACE level...
Definition: Logger.h:293
#define TE_CORE_LOG_INFO(channel, message)
Use this tag in order to log a message to a specified logger with the INFO level. ...
Definition: Logger.h:239
TECOREEXPORT std::string FindInTerraLibPath(const std::string &path)
Returns the path relative to a directory or file in the context of TerraLib.
#define TE_LOG_DEBUG(message)
Use this tag in order to log a message to the TerraLib default logger with the DEBUG level...
Definition: Logger.h:304
#define TE_LOG_ERROR(message)
Use this tag in order to log a message to the TerraLib default logger with the ERROR level...
Definition: Logger.h:337
An exception indicating that a given argument is not valid, for instance if a given item already exis...
#define TE_LOG_WARN(message)
Use this tag in order to log a message to the TerraLib default logger with the WARN level...
Definition: Logger.h:326
Exception classes for the TerraLib Core Runtime Library.
#define TE_CORE_LOG_TRACE(channel, message)
Use this tag in order to log a message to a specified logger with the TRACE level.
Definition: Logger.h:211
#define TE_CORE_LOG_WARN(channel, message)
Use this tag in order to log a message to a specified logger with the WARN level. ...
Definition: Logger.h:253