Commit c059e63b authored by Bart van der Velden's avatar Bart van der Velden

- Enabled Boost logging again

- Fixed a bug handling the command line
- Removed / suppressed a few warnings (#47)
parent 331af70e
......@@ -75,7 +75,9 @@ elseif(WIN32) # On Windows
add_definitions(/wd4355) # "'this': used in member initializer list
add_definitions(/wd4481) # nonstandard extension used: override specifier 'override'
add_definitions(/wd4505) # unreferenced function has been removed
add_definitions(/wd4510) # default constructor could not be generated
add_definitions(/wd4512) # assignment operator could not be generated
add_definitions(/wd4610) # can never be instantiated user defined constructor required
else()
message(FATAL_ERROR "Unsupported C++ compiler on Windows")
......@@ -93,7 +95,6 @@ endif()
# add_definitions(/wd4250) # inherits (implements) some member via dominance
# add_definitions(/wd4347) # "behavior change", function called instead of template
# add_definitions(/wd4355) # "'this': used in member initializer list
# add_definitions(/wd4510) # default constructor could not be generated
# add_definitions(/wd4511) # copy constructor could not be generated
# add_definitions(/wd4513) # destructor could not be generated
# add_definitions(/wd4623) # default constructor could not be generated
......
......@@ -18,6 +18,14 @@
#include <iostream>
#include <boost/program_options.hpp>
#include <boost/chrono.hpp>
// Boost log
#include "boost_log_trivial.h"
#include <boost/log/core.hpp>
#include <boost/log/sinks/text_file_backend.hpp>
#include <boost/log/utility/setup/file.hpp>
#include <boost/log/utility/setup/common_attributes.hpp>
#include "version.h"
#include "scandir.h"
#include "utils.h"
......@@ -33,16 +41,19 @@ namespace po = boost::program_options;
namespace chrono = boost::chrono;
namespace utils = mc::utils;
namespace logging = boost::log;
namespace keywords = boost::log::keywords;
static const int Second = 1000;
static const char* DefaultLogFile = "mc.log";
static const char* DefaultLogFile = "mc";
static const char* DefaultConfigFile = "musiccollection.cfg";
static const char* CopyrightNotice = "Copyright 2012-2013 Bart van der Velden";
void InitLogging(const string& logFile)
{
/* logging::add_file_log
logging::add_file_log
(
keywords::file_name = logFile + ".%N",
keywords::file_name = logFile + ".%N" + ".log",
keywords::open_mode = ios_base::out,
keywords::rotation_size = 10 * 1024 * 1024,
keywords::time_based_rotation = boost::log::sinks::file::rotation_at_time_point(0, 0, 0),
......@@ -55,7 +66,6 @@ void InitLogging(const string& logFile)
);
logging::add_common_attributes();
*/
}
// Parse the command line
......@@ -72,7 +82,7 @@ bool HandleCommandLine(int argc, char **argv, vector<string>& folders, string& l
desc.add_options()
("help,h", "show this help")
("version,v", "show version information")
("logfile", "the file to log to")
("logfile", po::value<string>(), "the file to log to")
("folder", po::value<vector<string> >(), "folder to scan");
po::store(po::command_line_parser(argc, argv).options(desc).positional(pod).run(), vm);
ifstream ifs(DefaultConfigFile);
......@@ -174,7 +184,7 @@ AudioFile::AudioFile(const TagLib::FileRef& fileRef)
int len = fileRef.file()->length();
TagLib::PropertyMap pm = fileRef.file()->properties();
TagLib::String s = pm.toString();
cout << "Properties:\n" << s.toWString() << endl;
BOOST_LOG_TRIVIAL(info) << "Properties:\n" << s.toWString();
TagLib::FileName fn = fileRef.file()->name();
}
......@@ -221,8 +231,8 @@ int main(int argc, char **argv)
{
InitLogging(logFile);
//using namespace logging::trivial;
//BOOST_LOG_TRIVIAL(info) << "Starting MusicCollection";
using namespace logging::trivial;
BOOST_LOG_TRIVIAL(info) << "Starting MusicCollection";
// Start timing
chrono::system_clock::time_point start = chrono::system_clock::now();
......@@ -233,7 +243,7 @@ int main(int argc, char **argv)
// Start a scanner for each given directory
for (auto it = folders.begin(); it != folders.end(); ++it)
{
cout << "Scanning " << *it << endl;
BOOST_LOG_TRIVIAL(info) << "Scanning " << *it;
// Prepare for long file names on Windows
fs::path path = utils::PrepareLongFileName(*it);
......@@ -264,7 +274,7 @@ int main(int argc, char **argv)
chrono::duration<double> sec = chrono::system_clock::now() - start;
std::cout << "Scanning took " << sec.count() << " seconds\n";
//BOOST_LOG_TRIVIAL(info) << "Stopping MusicCollection";
BOOST_LOG_TRIVIAL(info) << "Stopping MusicCollection";
}
else
{
......
......@@ -21,6 +21,8 @@
add_library(utils STATIC
scandir.cpp scandir.h
utils.cpp utils.h
boost_thread.h
boost_log_trivial.h
)
add_subdirectory(test)
/*****************************************************************************
* Copyright 2014 Bart van der Velden <bart@muckingabout.eu> *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
*****************************************************************************/
#ifndef MUSICCOLLECTION_UTILS_BOOST_LOG_TRIVIAL_H_INCLUDED
#define MUSICCOLLECTION_UTILS_BOOST_LOG_TRIVIAL_H_INCLUDED
// <boost/log/trivial.hpp> generates warnings with Microsoft Visual C++ on warning level 4
#ifdef _MSC_VER
#pragma warning(push, 3)
#endif
#include <boost/log/trivial.hpp>
#ifdef _MSC_VER
#pragma warning(pop)
#endif
#endif // MUSICCOLLECTION_UTILS_BOOST_LOG_TRIVIAL_H_INCLUDED
/*****************************************************************************
* Copyright 2014 Bart van der Velden <bart@muckingabout.eu> *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
*****************************************************************************/
#ifndef MUSICCOLLECTION_UTILS_BOOST_THREAD_H_INCLUDED
#define MUSICCOLLECTION_UTILS_BOOST_THREAD_H_INCLUDED
// <boost/thread.hpp> generates warnings with Microsoft Visual C++ on warning level 4
#ifdef _MSC_VER
#pragma warning(push, 3)
#endif
#include <boost/thread.hpp>
#ifdef _MSC_VER
#pragma warning(pop)
#endif
#endif // MUSICCOLLECTION_UTILS_BOOST_THREAD_H_INCLUDED
......@@ -23,10 +23,12 @@
#include "scandir.h"
#include <string>
#include <iostream>
#include "boost_log_trivial.h"
using namespace std;
namespace fs = boost::filesystem;
using namespace mc::utils;
namespace logging = boost::log;
// Start scanning Path recursively in a new thread
ScanDir::ScanDir(const fs::path& Path, IProcessFile* FileProcess)
......@@ -95,7 +97,7 @@ void ScanDir::DoWork()
fs::recursive_directory_iterator end;
if (ec)
{
cerr << "\nError! Errorcode = " << ec.value() << ": " << ec.message() << " (" << m_currentDir.string() << ")\n";
BOOST_LOG_TRIVIAL(error) << "\nError! Errorcode = " << ec.value() << ": " << ec.message() << " (" << m_currentDir.string();
}
while (it != end && !m_stopRequested)
......@@ -140,12 +142,14 @@ void ScanDir::DoWork()
}
catch (fs::filesystem_error& err)
{
cerr << err.what() << "\n";
BOOST_LOG_TRIVIAL(error) << err.what();
it.no_push();
}
}
m_finished = true;
cout << "Finished scanning " << m_startDir << endl;
using namespace logging::trivial;
BOOST_LOG_TRIVIAL(info) << "Finished scanning " << m_startDir;
m_stopRequested = true;
}
......@@ -22,7 +22,7 @@
#ifndef MUSICCOLLECTION_UTILS_SCANDIR_H_INCLUDED
#define MUSICCOLLECTION_UTILS_SCANDIR_H_INCLUDED
#include <boost/thread.hpp>
#include "boost_thread.h"
#include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment