Created basic logging module

This commit is contained in:
2016-06-30 15:53:24 +01:00
parent b0978f0ced
commit 2ba089aa74
6 changed files with 72 additions and 3 deletions
+1 -1
View File
@@ -1 +1 @@
-I ./include
-I ./include -std=c++11
+6 -2
View File
@@ -1,15 +1,19 @@
cmake_minimum_required(VERSION 3.5.2)
set(CMAKE_CXX_STANDARD 11)
# Set the project name
project (concatenator)
set(Boost_USE_STATIC_LIBS OFF)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
find_package(Boost 1.60.0 COMPONENTS program_options)
find_package(Boost 1.60.0 COMPONENTS program_options log log_setup thread date_time filesystem system)
if (NOT FO_BOOST_STATIC_LINK)
add_definitions(-DBOOST_ALL_NO_LIB -DBOOST_ALL_DYN_LINK -DBOOST_LOG_DYN_LINK)
endif()
# Set build flags
set(CMAKE_CXX_FLAGS "-g -Wall")
set(CMAKE_CXX_FLAGS "-g -Wall ")
# Set cmake to output executable to the bin directory
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
+19
View File
@@ -0,0 +1,19 @@
#include <boost/shared_ptr.hpp>
#include <boost/log/sinks.hpp>
#include <boost/log/sources/severity_logger.hpp>
class Logger {
public:
Logger();
~Logger() {};
void debug(std::string str);
void info(std::string str);
void warning(std::string str);
void error(std::string str);
void critical(std::string str);
private:
typedef boost::log::sinks::asynchronous_sink<boost::log::sinks::text_ostream_backend> text_sink;
boost::log::sources::severity_logger<int> lg;
boost::shared_ptr<text_sink> sink;
};
+1
View File
@@ -3,6 +3,7 @@
class AudioFile {
public:
private:
SndfileHandle file;
};
class AnalysedAudioFile : public AudioFile {
+3
View File
@@ -1,13 +1,16 @@
#include <iostream>
#include "Logger.h"
#include "ArgumentParser.h"
#include "AudioDatabase.h"
using namespace std;
int main(int argc, char** argv) {
Logger log = Logger();
ArgumentParser argparse = ArgumentParser();
argparse.parseargs(argc, argv);
log.error("My pretty little error!");
cout << "Hello world!" << endl;
return 0;
}
+42
View File
@@ -0,0 +1,42 @@
#include <boost/log/common.hpp>
#include <boost/log/sinks.hpp>
#include <boost/log/sources/severity_logger.hpp>
#include <boost/log/expressions.hpp>
#include <boost/utility/empty_deleter.hpp>
#include <boost/shared_ptr.hpp>
#include <iostream>
#include "Logger.h"
using namespace boost::log;
BOOST_LOG_ATTRIBUTE_KEYWORD(severity, "Severity", int)
Logger::Logger() {
Logger::sink = boost::make_shared<text_sink>();
boost::shared_ptr<std::ostream> stream{&std::clog, boost::empty_deleter{}};
Logger::sink->locked_backend()->add_stream(stream);
Logger::sink->set_filter(severity > 0);
Logger::sink->set_formatter(expressions::stream << severity << ": " <<
expressions::smessage);
core::get()->add_sink(Logger::sink);
};
void Logger::error(std::string str) {
BOOST_LOG_SEV(lg, 2) << str;
Logger::sink->flush();
}
void Logger::info(std::string str) {
BOOST_LOG_SEV(lg, 0) << str;
Logger::sink->flush();
}
void Logger::warning(std::string str) {
BOOST_LOG_SEV(lg, 1) << str;
Logger::sink->flush();
}