|
@@ -10,8 +10,8 @@
|
|
|
|
|
|
#include <boost/asio.hpp>
|
|
|
#include <boost/log/attributes.hpp>
|
|
|
-#include <boost/log/utility/setup/common_attributes.hpp>
|
|
|
#include <boost/log/core.hpp>
|
|
|
+#include <boost/log/utility/setup/common_attributes.hpp>
|
|
|
// #include <boost/log/sinks/text_file_backend.hpp>
|
|
|
#include <boost/log/trivial.hpp>
|
|
|
#include <boost/log/utility/setup/file.hpp>
|
|
@@ -24,27 +24,58 @@
|
|
|
#include "config.h"
|
|
|
#include "session.h"
|
|
|
|
|
|
-void init_logging(void) {
|
|
|
- /*
|
|
|
- std::ifstream file("log_settings.ini");
|
|
|
- if (!file.is_open()) {
|
|
|
- std::cerr << "Could not open log_settings.ini file." << std::endl;
|
|
|
- exit(1);
|
|
|
- }
|
|
|
+#include <boost/date_time/posix_time/posix_time_types.hpp>
|
|
|
+#include <boost/log/expressions.hpp>
|
|
|
|
|
|
- boost::log::init_from_stream(file);
|
|
|
- */
|
|
|
- // boost::log::add_file_log("proxy.log"); // WAT?
|
|
|
- // boost::shared_ptr< boost::log::core > core = boost::log::core::get();
|
|
|
- // core->add_global_attribute("TimeStamp", boost::attrs::local_clock());
|
|
|
+/*
|
|
|
+boost log linking -
|
|
|
+undefined reference to `void boost::log::v2_mt_posix::init_from_stream
|
|
|
+https://github.com/boostorg/log/issues/46
|
|
|
+ */
|
|
|
+
|
|
|
+void init_logging(void) {
|
|
|
+ // because TimeStamp is missing by default.
|
|
|
boost::log::add_common_attributes();
|
|
|
|
|
|
+ auto fmtScope = boost::log::expressions::format_named_scope(
|
|
|
+ "Scope", boost::log::keywords::format = "%n(%f:%l)",
|
|
|
+ // boost::log::keywords::iteration = boost::log::expressions::reverse,
|
|
|
+ boost::log::keywords::depth = 2);
|
|
|
+
|
|
|
+ auto fmtTimeStamp =
|
|
|
+ boost::log::expressions::format_date_time<boost::posix_time::ptime>(
|
|
|
+ "TimeStamp", "%Y-%m-%d %H:%M:%S.%f");
|
|
|
+
|
|
|
boost::log::add_file_log(
|
|
|
- boost::log::keywords::file_name = "proxy.log",
|
|
|
- boost::log::keywords::format = "[%TimeStamp%]: %Message%"
|
|
|
+ // This gives dated logfile name.
|
|
|
+ boost::log::keywords::file_name = "proxy-%Y-%m-%d.log",
|
|
|
+ // This appends to the logfile (instead of overwrite)
|
|
|
+ boost::log::keywords::open_mode = std::ios_base::out | std::ios_base::app,
|
|
|
+
|
|
|
+ boost::log::keywords::format =
|
|
|
+ (boost::log::expressions::stream <<
|
|
|
+ // <<
|
|
|
+ // boost::log::expressions::attr<boost::posix_time::ptime>("TimeStamp")
|
|
|
+ // <<
|
|
|
+ fmtTimeStamp <<
|
|
|
+ // << boost::log::expressions::attr<unsigned int>("LineID") <<
|
|
|
+ ": <" << boost::log::trivial::severity << " [" << fmtScope << "] "
|
|
|
+ << "> "
|
|
|
+ << boost::log::expressions::smessage)
|
|
|
+
|
|
|
+ // boost::log::keywords::format = "[%TimeStamp%] %Severity% %Scope% :
|
|
|
+ // %Message%",
|
|
|
);
|
|
|
- boost::log::core::get()->set_filter(boost::log::trivial::severity >=
|
|
|
- boost::log::trivial::info);
|
|
|
+
|
|
|
+ auto core = boost::log::core::get();
|
|
|
+ // boost::log::core::get()->set_filter(boost::log::trivial::severity >=
|
|
|
+ // boost::log::trivial::info);
|
|
|
+ core->set_filter(boost::log::trivial::severity >= boost::log::trivial::info);
|
|
|
+ // core->add_global_attribute("Scopes", boost::log::keywords::format = "%n
|
|
|
+ // (%f:%l)"); core->set_formatter("Scopes", boost::log::keywords::format = "%n
|
|
|
+ // (%f:%l)"); logging::core::get()->add_global_attribute("Scopes",
|
|
|
+ // attributes::named_scope());
|
|
|
+ core->add_global_attribute("Scope", boost::log::attributes::named_scope());
|
|
|
}
|
|
|
|
|
|
int main(int argc, char *argv[]) {
|