forked from hxmhuang/OpenArray_Dev
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlog.cpp
More file actions
71 lines (57 loc) · 2.85 KB
/
log.cpp
File metadata and controls
71 lines (57 loc) · 2.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#ifndef __LOG_CPP__
#define __LOG_CPP__
#include <iostream>
#include <boost/log/common.hpp>
#include <boost/log/expressions.hpp>
#include <boost/log/utility/setup/file.hpp>
#include <boost/log/utility/setup/console.hpp>
#include <boost/log/utility/setup/common_attributes.hpp>
#include <boost/log/attributes/timer.hpp>
#include <boost/log/attributes/named_scope.hpp>
#include <boost/log/sources/logger.hpp>
#include <boost/log/support/date_time.hpp>
#include "log.hpp"
//namespace logging = boost::log;
//namespace sinks = boost::log::sinks;
//namespace attrs = boost::log::attributes;
//namespace src = boost::log::sources;
//namespace expr = boost::log::expressions;
//namespace keywords = boost::log::keywords;
using boost::shared_ptr;
namespace oa {
namespace logging{
extern void logging_start(int world_rank){
boost::log::add_console_log(std::clog, boost::log::keywords::format = "%TimeStamp%: %Message%");
boost::log::add_file_log
(
"monitor_in_thread_"+std::to_string(world_rank)+".log",
boost::log::keywords::filter = boost::log::expressions::attr< severity_level >("Severity") >= warning,
boost::log::keywords::format = boost::log::expressions::stream
<< boost::log::expressions::format_date_time< boost::posix_time::ptime >("TimeStamp", "%Y-%m-%d, %H:%M:%S.%f")
<< " [" << boost::log::expressions::format_date_time< boost::log::attributes::timer::value_type >("Uptime", "%O:%M:%S")
<< "] [" << boost::log::expressions::format_named_scope("Scope", boost::log::keywords::format = "%n (%f:%l)")
<< "] <" << boost::log::expressions::attr< severity_level >("Severity")
<< "> " << boost::log::expressions::message
);
boost::log::add_common_attributes();
boost::log::core::get()->add_thread_attribute("Scope", boost::log::attributes::named_scope());
BOOST_LOG_FUNCTION();
}
extern void write_log(int world_rank){
boost::log::sources::logger lg;
BOOST_LOG(lg) << "Hello, World!";
boost::log::sources::severity_logger< severity_level > slg;
slg.add_attribute("Uptime", boost::log::attributes::timer());
BOOST_LOG_SEV(slg, normal) <<"Thread_"+std::to_string(world_rank)+": A normal severity message, will not pass to the file";
BOOST_LOG_SEV(slg, warning) <<"Thread_"+std::to_string(world_rank)+": A warning severity message, will pass to the file";
BOOST_LOG_SEV(slg, error) << "Thread_"+std::to_string(world_rank)+": An error severity message, will pass to the file";
}
extern void write_log_error(int world_rank, std::string function_name){
boost::log::sources::severity_logger< severity_level > slg;
slg.add_attribute("Uptime", boost::log::attributes::timer());
std::cout<<function_name<<std::endl;
BOOST_LOG_SEV(slg, error) << "Thread_"+std::to_string(world_rank)+": An error severity message,in the funcion of "+function_name;
}
}
}
#endif