-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
113 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#ifndef KEYCHAIN_LOGGER | ||
#define KEYCHAIN_LOGGER | ||
|
||
#include <boost/log/trivial.hpp> | ||
|
||
namespace logging = boost::log; | ||
namespace src = boost::log::sources; | ||
namespace sinks = boost::log::sinks; | ||
namespace keywords = boost::log::keywords; | ||
namespace expr = boost::log::expressions; | ||
|
||
using namespace logging::trivial; | ||
|
||
|
||
class logger_singletone | ||
{ | ||
public: | ||
logger_singletone(); | ||
static const logger_singletone& instance(); | ||
src::severity_logger< severity_level > lg; | ||
}; | ||
|
||
#endif //KEYCHAIN_LOGGER |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#include "keychain_logger.hpp" | ||
|
||
#include <boost/log/core.hpp> | ||
#include <boost/log/expressions.hpp> | ||
#include <boost/log/utility/setup/file.hpp> | ||
#include <boost/log/utility/setup/common_attributes.hpp> | ||
#include <boost/log/sources/severity_logger.hpp> | ||
#include <boost/log/sources/record_ostream.hpp> | ||
#include <boost/log/sinks/text_ostream_backend.hpp> | ||
#include <boost/core/null_deleter.hpp> | ||
#include <boost/date_time/posix_time/posix_time.hpp> | ||
#include <fstream> | ||
|
||
|
||
logger_singletone::logger_singletone() | ||
{ | ||
logging::add_file_log | ||
( | ||
keywords::file_name = "sample_%N.log", | ||
keywords::rotation_size = 10 * 1024 * 1024, | ||
keywords::time_based_rotation = sinks::file::rotation_at_time_point(0, 0, 0), | ||
keywords::format = "[%TimeStamp%]: %Message%" | ||
); | ||
|
||
boost::shared_ptr< logging::core > core = logging::core::get(); | ||
|
||
logging::add_common_attributes(); | ||
|
||
// Create a backend and attach a couple of streams to it | ||
boost::shared_ptr< sinks::text_ostream_backend > backend = | ||
boost::make_shared< sinks::text_ostream_backend >(); | ||
backend->add_stream( | ||
boost::shared_ptr< std::ostream >(new std::ofstream("sample.log"))); | ||
// Enable auto-flushing after each log record written | ||
backend->auto_flush(true); | ||
|
||
typedef sinks::synchronous_sink< sinks::text_ostream_backend > sink_t; | ||
boost::shared_ptr< sink_t > sink(new sink_t(backend)); | ||
|
||
sink->set_formatter( | ||
expr::format("%1% %2% %3%") | ||
% expr::attr< boost::posix_time::ptime >("TimeStamp") | ||
% expr::attr< severity_level >("Severity") | ||
% expr::message | ||
); | ||
|
||
core->add_sink(sink); | ||
|
||
} | ||
|
||
const logger_singletone& logger_singletone::instance() | ||
{ | ||
static const logger_singletone instance; | ||
return instance; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters