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/image.cpp | 7 +-- src/base/image.hpp | 4 +- src/base/song.cpp | 24 ++++----- src/base/song.hpp | 4 +- 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 +- src/base/stats.hpp | 4 +- src/base/texture.cpp | 7 +-- src/base/texture.hpp | 3 +- src/frames/loading_frame.cpp | 4 +- src/frames/loading_frame.hpp | 4 +- src/menu/application.cpp | 12 +++-- src/menu/application.hpp | 4 +- src/menu/event_manager.cpp | 6 +-- src/menu/event_manager.hpp | 4 +- 17 files changed, 91 insertions(+), 75 deletions(-) (limited to 'src') diff --git a/src/base/image.cpp b/src/base/image.cpp index 7b06cc3e..753c8ec3 100644 --- a/src/base/image.cpp +++ b/src/base/image.cpp @@ -30,8 +30,8 @@ namespace usdx { - log4cxx::LoggerPtr Image::log = - log4cxx::Logger::getLogger("usdx.base.Image"); + log4cpp::Category& Image::log = + log4cpp::Category::getInstance("usdx.base.Image"); ImageLoadException::ImageLoadException(std::string error) : error(error) @@ -68,7 +68,8 @@ namespace usdx surface = IMG_Load_RW(source, 1); if (surface == NULL) { - LOG4CXX_ERROR(log, "Error loading image: " << filename); + log << log4cpp::Priority::ERROR << + "Error loading image: " << filename; throw ImageLoadException(IMG_GetError()); } } diff --git a/src/base/image.hpp b/src/base/image.hpp index 9e9ea6e4..4c9d911e 100644 --- a/src/base/image.hpp +++ b/src/base/image.hpp @@ -31,7 +31,7 @@ #include #include #include -#include +#include namespace usdx { @@ -50,7 +50,7 @@ namespace usdx class Image { private: - static log4cxx::LoggerPtr log; + static log4cpp::Category& log; boost::filesystem::wpath filename; SDL_Surface* surface; diff --git a/src/base/song.cpp b/src/base/song.cpp index 209f13de..af7e90a5 100644 --- a/src/base/song.cpp +++ b/src/base/song.cpp @@ -30,8 +30,8 @@ namespace usdx { - log4cxx::LoggerPtr Song::log = - log4cxx::Logger::getLogger("usdx.base.Song"); + log4cpp::Category& Song::log = + log4cpp::Category::getInstance("usdx.base.Song"); const boost::filesystem::wpath& Song::get_filename(void) const { @@ -98,7 +98,7 @@ namespace usdx lyrics.clear(); } - std::string Song::get_header_tag(const std::string& tag, const bool required) + std::string Song::get_header_tag(const std::string& tag, const bool required) { std::map::iterator it; std::string result = ""; @@ -108,9 +108,9 @@ namespace usdx custom_header_tags.erase(it); } else if (required) { - LOG4CXX_ERROR(log, "Incomplete Song! Missing '" << tag << "' Tag in: '" << - get_filename() << "'"); - throw MissingTagException(tag, "Incomplete Song! Missing Tag."); + log << log4cpp::Priority::ERROR << "Incomplete Song! Missing '" << + tag << "' Tag in: '" << get_filename() << "'"; + throw MissingTagException(tag, "Incomplete Song! Missing Tag."); } return result; @@ -126,8 +126,8 @@ namespace usdx custom_header_tags.erase(it); } else if (required) { - LOG4CXX_ERROR(log, "Incomplete Song! Missing '" << tag << "' Tag in: '" << - get_filename() << "'"); + log << log4cpp::Priority::ERROR << "Incomplete Song! Missing '" << + tag << "' Tag in: '" << get_filename() << "'"; throw MissingTagException(tag, "Incomplete Song! Missing Tag."); } @@ -145,8 +145,8 @@ namespace usdx stream >> result; } else if (required) { - LOG4CXX_ERROR(log, "Incomplete Song! Missing '" << tag << "' Tag in: '" << - get_filename() << "'"); + log << log4cpp::Priority::ERROR << "Incomplete Song! Missing '" << + tag << "' Tag in: '" << get_filename() << "'"; throw MissingTagException(tag, "Incomplete Song! Missing Tag."); } @@ -167,8 +167,8 @@ namespace usdx custom_header_tags.erase(it); } else if (required) { - LOG4CXX_ERROR(log, "Incomplete Song! Missing '" << tag << "' Tag in: '" << - get_filename() << "'"); + log << log4cpp::Priority::ERROR << "Incomplete Song! Missing '" << + tag << "' Tag in: '" << get_filename() << "'"; throw MissingTagException(tag, "Incomplete Song! Missing Tag."); } diff --git a/src/base/song.hpp b/src/base/song.hpp index c5b160af..afcae7f4 100644 --- a/src/base/song.hpp +++ b/src/base/song.hpp @@ -31,7 +31,7 @@ #include #include #include -#include +#include #include "bpm.hpp" #include "lyric_line.hpp" #include "texture.hpp" @@ -60,7 +60,7 @@ namespace usdx class Song { private: - static log4cxx::LoggerPtr log; + static log4cpp::Category& log; boost::filesystem::wpath filename; 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. diff --git a/src/base/stats.hpp b/src/base/stats.hpp index b3068024..63d3a68e 100644 --- a/src/base/stats.hpp +++ b/src/base/stats.hpp @@ -28,7 +28,7 @@ #define STATS_HPP #include -#include +#include #include "stats_database.hpp" namespace usdx @@ -39,7 +39,7 @@ namespace usdx class Stats { private: - static log4cxx::LoggerPtr log; + static log4cpp::Category& log; static StatDatabase *db; static std::string filename; diff --git a/src/base/texture.cpp b/src/base/texture.cpp index ee26a5c8..cf24b9ce 100644 --- a/src/base/texture.cpp +++ b/src/base/texture.cpp @@ -28,8 +28,8 @@ namespace usdx { - log4cxx::LoggerPtr Texture::log = - log4cxx::Logger::getLogger("usdx.base.texture"); + log4cpp::Category& Texture::log = + log4cpp::Category::getInstance("usdx.base.texture"); Texture::Texture(boost::filesystem::wpath filename) : filename(filename), texture(0), size(0, 0), rotation(0) @@ -73,7 +73,8 @@ namespace usdx break; default: - LOG4CXX_ERROR(log, "" << filename << " is not in true color! Could not handle that!"); + log << log4cpp::Priority::ERROR << "'" << filename << + "' is not in true color! Could not handle that!"; throw TextureColorDepthException(image.get_surface()->format->BytesPerPixel); } diff --git a/src/base/texture.hpp b/src/base/texture.hpp index 008707d6..fbd88197 100644 --- a/src/base/texture.hpp +++ b/src/base/texture.hpp @@ -29,6 +29,7 @@ #include #include +#include #include "utils/point_3d.hpp" #include "utils/dimension.hpp" @@ -68,7 +69,7 @@ namespace usdx class Texture { private: - static log4cxx::LoggerPtr log; + static log4cpp::Category& log; boost::filesystem::wpath filename; diff --git a/src/frames/loading_frame.cpp b/src/frames/loading_frame.cpp index afaa7d0b..fac163d6 100644 --- a/src/frames/loading_frame.cpp +++ b/src/frames/loading_frame.cpp @@ -30,8 +30,8 @@ namespace usdx { - log4cxx::LoggerPtr LoadingFrame::log = - log4cxx::Logger::getLogger("usdx.frames.loading_frame"); + log4cpp::Category& LoadingFrame::log = + log4cpp::Category::getInstance("usdx.frames.loading_frame"); LoadingFrame::LoadingFrame() : Frame(NULL) diff --git a/src/frames/loading_frame.hpp b/src/frames/loading_frame.hpp index 5ddf0bf4..80ef0951 100644 --- a/src/frames/loading_frame.hpp +++ b/src/frames/loading_frame.hpp @@ -28,14 +28,14 @@ #define LOADING_FRAME_HPP #include "frame.hpp" -#include +#include namespace usdx { class LoadingFrame : public Frame { private: - static log4cxx::LoggerPtr log; + static log4cpp::Category& log; public: LoadingFrame(); diff --git a/src/menu/application.cpp b/src/menu/application.cpp index 37e532a2..d34b8003 100644 --- a/src/menu/application.cpp +++ b/src/menu/application.cpp @@ -30,11 +30,12 @@ #include "software_mouse_pointer.hpp" #include "loading_frame.hpp" #include +#include namespace usdx { - log4cxx::LoggerPtr Application::log = - log4cxx::Logger::getLogger("usdx.menu.application"); + log4cpp::Category& Application::log = + log4cpp::Category::getInstance("usdx.menu.application"); Application* Application::instance = NULL; @@ -43,6 +44,7 @@ namespace usdx fps_manager(NULL), running(false), display_width(800), display_height(600), frames_per_second(50) { + log4cpp::PropertyConfigurator::configure("log4cpp.property"); SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO); } @@ -119,7 +121,7 @@ namespace usdx repaint(); SDL_GL_SwapBuffers(); - LOG4CXX_TRACE(log, "repaint"); + log << log4cpp::Priority::DEBUG << "repaint"; // poll current events while (event_manager.available() && SDL_PollEvent(&event)) { @@ -185,8 +187,8 @@ namespace usdx } if (! display) { - LOG4CXX_ERROR(log, "SDL_SetVideoMode failed."); - throw new std::exception(); + log << log4cpp::Priority::ERROR << "SDL_SetVideoMode failed."; + throw new std::exception(); } init_fps_manager(); diff --git a/src/menu/application.hpp b/src/menu/application.hpp index 914eda71..5564c1ad 100644 --- a/src/menu/application.hpp +++ b/src/menu/application.hpp @@ -29,7 +29,7 @@ #include #include -#include +#include #include #include "drawable_control.hpp" @@ -40,7 +40,7 @@ namespace usdx class Application : public DrawableControl { private: - static log4cxx::LoggerPtr log; + static log4cpp::Category& log; static Application* instance; SDL_Surface* display; diff --git a/src/menu/event_manager.cpp b/src/menu/event_manager.cpp index 8f09f202..7359d77c 100644 --- a/src/menu/event_manager.cpp +++ b/src/menu/event_manager.cpp @@ -29,8 +29,8 @@ namespace usdx { - log4cxx::LoggerPtr EventManager::log = - log4cxx::Logger::getLogger("usdx.menu.event_manager"); + log4cpp::Category& EventManager::log = + log4cpp::Category::getInstance("usdx.menu.event_manager"); EventManager::EventManager(int capacity) : buffer(capacity), waiting(0) @@ -100,7 +100,7 @@ namespace usdx switch (event.type) { case SDL_KEYDOWN: - LOG4CXX_ERROR(log, "key"); + log << log4cpp::Priority::ERROR << "key"; break; case SDL_MOUSEMOTION: diff --git a/src/menu/event_manager.hpp b/src/menu/event_manager.hpp index bfdda35b..e20950cb 100644 --- a/src/menu/event_manager.hpp +++ b/src/menu/event_manager.hpp @@ -38,7 +38,7 @@ #include #include -#include +#include namespace usdx { @@ -52,7 +52,7 @@ namespace usdx class EventManager { private: - static log4cxx::LoggerPtr log; + static log4cpp::Category& log; EventManager(const EventManager&); //< no copy EventManager& operator=(const EventManager&); //< no assignment -- cgit v1.2.3