From 53bd23d0e679746b78d0bcf9234e7b99983e6071 Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Tue, 29 Nov 2011 04:52:52 +0100 Subject: ported from log4cxx to log4cpp log4cxx depends on Apache Portable Runtime Utility Library, so we switch to log4cpp with nearly the same features but with no dependencies for easier porting to other platforms --- src/base/songloading/songloader.cpp | 12 +++-- src/base/songloading/songloader.hpp | 4 +- src/base/songloading/songloading_strategy_txt.cpp | 59 +++++++++++++---------- src/base/songloading/songloading_strategy_txt.hpp | 4 +- 4 files changed, 45 insertions(+), 34 deletions(-) (limited to 'src/base/songloading') diff --git a/src/base/songloading/songloader.cpp b/src/base/songloading/songloader.cpp index 5562bdc7..5b46601b 100644 --- a/src/base/songloading/songloader.cpp +++ b/src/base/songloading/songloader.cpp @@ -30,8 +30,8 @@ namespace usdx { - log4cxx::LoggerPtr Songloader::log = - log4cxx::Logger::getLogger("usdx.base.songloading.Songloader"); + log4cpp::Category& Songloader::log = + log4cpp::Category::getInstance("usdx.base.songloading.Songloader"); Songloader *Songloader::instance = NULL; @@ -61,7 +61,9 @@ namespace usdx std::string ext = extension(filename); std::map::iterator it = strategies.find(ext); if (it == strategies.end()) { - LOG4CXX_WARN(log, "No SongloadingStrategy found for file extension: '" << ext << "'"); + log << log4cpp::Priority::WARN << + "No SongloadingStrategy found for file extension: '" << + ext << "'"; throw NoStrategyException("Unknown file format."); } @@ -73,7 +75,9 @@ namespace usdx std::string ext = extension(song->get_filename()); std::map::iterator it = strategies.find(ext); if (it == strategies.end()) { - LOG4CXX_WARN(log, "No SongloadingStrategy found for file extension: '" << ext << "'"); + log << log4cpp::Priority::WARN << + "No SongloadingStrategy found for file extension: '" << + ext << "'"; throw NoStrategyException("Unknown file format."); } diff --git a/src/base/songloading/songloader.hpp b/src/base/songloading/songloader.hpp index 4b7150ab..0f9611fe 100644 --- a/src/base/songloading/songloader.hpp +++ b/src/base/songloading/songloader.hpp @@ -29,7 +29,7 @@ #include #include -#include +#include #include "song.hpp" #include "utils/base_exception.hpp" #include "songloading_strategy_base_factory.hpp" @@ -46,7 +46,7 @@ namespace usdx class Songloader { private: - static log4cxx::LoggerPtr log; + static log4cpp::Category& log; Songloader(void); diff --git a/src/base/songloading/songloading_strategy_txt.cpp b/src/base/songloading/songloading_strategy_txt.cpp index a7d296a5..d3551144 100644 --- a/src/base/songloading/songloading_strategy_txt.cpp +++ b/src/base/songloading/songloading_strategy_txt.cpp @@ -36,9 +36,9 @@ namespace usdx { - log4cxx::LoggerPtr SongloadingStrategyTxt::log = - log4cxx::Logger::getLogger( - "usdx.base.songloading.SongloadingStrategyTxt"); + log4cpp::Category& SongloadingStrategyTxt::log = + log4cpp::Category::getInstance( + "usdx.base.songloading.SongloadingStrategyTxt"); SongloadingStrategyTxt::SongloadingStrategyTxt(void) { @@ -53,7 +53,8 @@ namespace usdx std::size_t pos = line.find(':'); if (line[0] != '#' || pos == std::string::npos) { - LOG4CXX_DEBUG(log, "Tried to parse invalid header line: '" << line << "'"); + log << log4cpp::Priority::DEBUG << + "Tried to parse invalid header line: '" << line << "'"; throw "Invalid header!"; } @@ -73,14 +74,16 @@ namespace usdx // line is already rtrimmed boost::trim_left(result.second); - LOG4CXX_DEBUG(log, "Found header: '" << result.first << "' with value '" << result.second << "'"); + log << log4cpp::Priority::DEBUG << "Found header: '" << + result.first << "' with value '" << result.second << "'"; return result; } Song* SongloadingStrategyTxt::load_song(Song *song) { - LOG4CXX_DEBUG(log, "Starting loading song from file: " << song->get_filename()); + log << log4cpp::Priority::DEBUG << + "Starting loading song from file: " << song->get_filename(); TextFile file(song->get_filename()); @@ -108,8 +111,10 @@ namespace usdx else if (type == 'E') { // song end if (file.stream().eof()) { - LOG4CXX_WARN(log, "End marker found in line " << line_number << - " before end of file: '" << song->get_filename() << "'."); + log << log4cpp::Priority::WARN << + "End marker found in line " << line_number << + " before end of file: '" << song->get_filename() << + "'."; } return false; @@ -124,14 +129,16 @@ namespace usdx parse_note(song, type, linestream, line_number); } else { - LOG4CXX_WARN(log, "Unknown line in song: '" << line << + log << log4cpp::Priority::WARN << + "Unknown line in song: '" << line << "' in file: " << song->get_filename() << - " at line " << line_number); + " at line " << line_number; } } catch (std::exception &e) { - LOG4CXX_WARN(log, "Error in song file at line " << - line_number << ": " << e.what()); + log << log4cpp::Priority::WARN << + "Error in song file at line " << line_number << ": " << + e.what(); } return true; @@ -145,14 +152,13 @@ namespace usdx linestream >> line_out; if (linestream.good()) { linestream >> line_in; - LOG4CXX_DEBUG(log, "Found newline in line " << - line_number << " with out of last line with " << - line_out << " and in of next line " << line_in); + log << log4cpp::Priority::DEBUG << "Found newline in line " << + line_number << " with out of last line with " << + line_out << " and in of next line " << line_in; } else { - LOG4CXX_DEBUG(log, "Found newline in line " << - line_number << " with out of last line with " << - line_out); + log << log4cpp::Priority::DEBUG << "Found newline in line " << + line_number << " with out of last line with " << line_out; } song->new_line(line_out, line_in); @@ -165,9 +171,9 @@ namespace usdx LocaleIndependentFloat new_bpm; linestream >> beat >> new_bpm; - LOG4CXX_DEBUG(log, "Found new bpm in line " << - line_number << " starting at beat: " << - beat << " and new bpm of " << new_bpm.get_value()); + log << log4cpp::Priority::DEBUG << "Found new bpm in line " << + line_number << " starting at beat: " << beat << + " and new bpm of " << new_bpm.get_value(); song->new_bpm(beat, new_bpm.get_value()); } @@ -182,9 +188,9 @@ namespace usdx getline(linestream, lyric); boost::trim_right_if(lyric, boost::is_cntrl()); - LOG4CXX_DEBUG(log, "Found lyric: '" << lyric << "' at line: " << line_number << - " at beat: " << beat << " with length: " << length << - " at height: " << height); + log << log4cpp::Priority::DEBUG << "Found lyric: '" << lyric << + "' at line: " << line_number << " at beat: " << beat << + " with length: " << length << " at height: " << height; song->new_note(type, beat, length, height, lyric); } @@ -200,7 +206,7 @@ namespace usdx boost::trim(line); boost::trim_if(line, boost::is_cntrl()); - LOG4CXX_DEBUG(log, "Line: " << line); + log << log4cpp::Priority::DEBUG << "Line: " << line; if (header && line[0] == '#') { @@ -221,7 +227,8 @@ namespace usdx } if (! notes_found) { - LOG4CXX_WARN(log, "Song: '" << filename << "' has no notes. Ignoring!"); + log << log4cpp::Priority::WARN << "Song: '" << filename << + "' has no notes. Ignoring!"; throw "No notes."; } diff --git a/src/base/songloading/songloading_strategy_txt.hpp b/src/base/songloading/songloading_strategy_txt.hpp index 293c65e6..5028304b 100644 --- a/src/base/songloading/songloading_strategy_txt.hpp +++ b/src/base/songloading/songloading_strategy_txt.hpp @@ -29,7 +29,7 @@ #include #include -#include +#include #include "songloading_strategy.hpp" #include "songloading_strategy_factory.hpp" #include "utils/text_file.hpp" @@ -39,7 +39,7 @@ namespace usdx class SongloadingStrategyTxt : public SongloadingStrategy { private: - static log4cxx::LoggerPtr log; + static log4cpp::Category& log; /** * Split the header field in name and value. -- cgit v1.2.3