Logger.cpp
Go to the documentation of this file.
00001 
00002 
00003 #include "nasa_common_logging/Logger.h"
00004 
00005 using namespace log4cpp;
00006 
00007 namespace NasaCommonLogging
00008 {
00009     Logger::Logger()
00010         : propertyFile("log4cpp.properties")
00011         , packagePath(ros::package::getPath("nasa_common_logging"))
00012     {
00013         std::string localPropertyFile = "./" + propertyFile;
00014 
00015         try
00016         {
00017             PropertyConfigurator::configure(localPropertyFile);
00018         }
00019         catch (ConfigureFailure& e)
00020         {
00021             if (not (std::string(e.what()) == "File " + localPropertyFile + " does not exist"))
00022             {
00023                 std::cerr << "WARN: Could not load local dir property file [" << localPropertyFile <<  "]: " << e.what() << std::endl;
00024             }
00025 
00026             std::string packagePropertyFile = packagePath + "/share/" + propertyFile;
00027 
00028             try
00029             {
00030                 PropertyConfigurator::configure(packagePropertyFile);
00031             }
00032             catch (ConfigureFailure& e)
00033             {
00034                 std::cerr << "WARN: Could not load package dir property file [" << packagePropertyFile <<  "]: " << e.what() << std::endl;
00035 
00036                 Appender* rootAppender = new OstreamAppender("root", &std::cout);
00037                 Layout* rootLayout = new BasicLayout();
00038                 rootAppender->setLayout(rootLayout);
00039                 Category::getRoot().addAppender(rootAppender);
00040                 Category::getRoot().setPriority(Priority::WARN);
00041 
00042                 Category::getRoot().log(Priority::WARN, "Could not load local dir or package dir property file: " + std::string(e.what()) + ". Using defaults of [std::out] and [WARN].");
00043             }
00044         }
00045     }
00046 
00047     Logger::~Logger()
00048     {
00049     }
00050 
00051     void Logger::log(const std::string& category, log4cpp::Priority::Value priority, const std::string& message)
00052     {
00053         getCategory(category).log(priority, message);
00054     }
00055 
00056     log4cpp::Category& Logger::getCategory(const std::string& category)
00057     {
00058         return Category::getInstance(category);
00059     }
00060 
00061     static Logger singleton;
00062 }


nasa_common_logging
Author(s):
autogenerated on Sun Feb 3 2019 03:42:09