include iostream include string include vector include logger VXLOG_DE

 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
72
73
74
75
76
77
78
79
80
81
#include <iostream>
#include <string>
#include <vector>
#include <logger.h>
VXLOG_DEFINE_MODULE( mLOGGER, "Logger module" );
ECSP_NAMESPACE_BEGIN(core)
static std::vector<LoggerModuleInitializer> loggModules;
class Logger
{
vxcommon::SharedPtr< vxlog::OutputterInterface > outputter;
public:
Logger()
{
outputter = vxcommon::SharedPtr< vxlog::OutputterInterface >( new vxlog::ConsoleOutputter() );
vxlog::InitModule( mLOGGER, vxlog::Level::kInfo, outputter );
vxlog::Info(mLOGGER, "ECSP logger is initialized\n");
}
Logger( const std::string &logFileName )
{
vxlog::FileOutputter *fileOutputter = new vxlog::FileOutputter();
int res = fileOutputter->Init( logFileName.c_str(), false, 0644 );
if (res)
{
delete fileOutputter;
std::cerr << "Failed to initialize file outputter: "
<< strerror(res) << std::endl;
exit(1);
}
else
{
outputter = vxcommon::SharedPtr< vxlog::OutputterInterface >( fileOutputter );
}
vxlog::Info(mLOGGER, "ECSP logger is initialized\n");
}
~Logger()
{
}
vxcommon::SharedPtr< vxlog::OutputterInterface > GetOutputter()
{
return outputter;
}
};
static Logger logger;
ECSP_NAMESPACE_END
bool LoggerRegisterModuleInitializer( LoggerModuleInitializer initCB )
{
ECSP::core::loggModules.push_back( initCB );
return true;
}
bool LoggerInit()
{
vxcommon::SharedPtr<vxlog::OutputterInterface> outputter = ECSP::core::logger.GetOutputter();
for ( uint32_t i = 0; i < ECSP::core::loggModules.size(); ++i )
{
ECSP::core::loggModules[i]( outputter );
}
return true;
}
bool LoggerRegisterAndUpdateModule( LoggerModuleInitializer initCB )
{
vxcommon::SharedPtr<vxlog::OutputterInterface> outputter = ECSP::core::logger.GetOutputter();
initCB( outputter );
return true;
}