Skip to content

[ISSUE #458] change log module #462

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,18 @@ else ()
#find_package(Boost 1.56 REQUIRED COMPONENTS atomic thread system chrono date_time log log_setup regex serialization filesystem locale iostreams)
set(Boost_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/bin/include)
set(Boost_LIBRARY_DIRS ${PROJECT_SOURCE_DIR}/bin/lib)
set(Boost_LIBRARIES ${Boost_LIBRARY_DIRS}/libboost_atomic.a;${Boost_LIBRARY_DIRS}/libboost_thread.a;${Boost_LIBRARY_DIRS}/libboost_system.a;
${Boost_LIBRARY_DIRS}/libboost_chrono.a;${Boost_LIBRARY_DIRS}/libboost_date_time.a;${Boost_LIBRARY_DIRS}/libboost_log.a;
${Boost_LIBRARY_DIRS}/libboost_log_setup.a;${Boost_LIBRARY_DIRS}/libboost_regex.a;${Boost_LIBRARY_DIRS}/libboost_serialization.a;
${Boost_LIBRARY_DIRS}/libboost_filesystem.a;${Boost_LIBRARY_DIRS}/libboost_locale.a;${Boost_LIBRARY_DIRS}/libboost_iostreams.a)
if (Boost_USE_STATIC_LIBS)
set(Boost_LIBRARIES ${Boost_LIBRARY_DIRS}/libboost_atomic.a;${Boost_LIBRARY_DIRS}/libboost_thread.a;${Boost_LIBRARY_DIRS}/libboost_system.a;
${Boost_LIBRARY_DIRS}/libboost_chrono.a;${Boost_LIBRARY_DIRS}/libboost_date_time.a;${Boost_LIBRARY_DIRS}/libboost_log.a;
${Boost_LIBRARY_DIRS}/libboost_log_setup.a;${Boost_LIBRARY_DIRS}/libboost_regex.a;${Boost_LIBRARY_DIRS}/libboost_serialization.a;
${Boost_LIBRARY_DIRS}/libboost_filesystem.a;${Boost_LIBRARY_DIRS}/libboost_locale.a;${Boost_LIBRARY_DIRS}/libboost_iostreams.a)
else ()
set(Boost_LIBRARIES ${Boost_LIBRARY_DIRS}/libboost_atomic.so;${Boost_LIBRARY_DIRS}/libboost_thread.so;${Boost_LIBRARY_DIRS}/libboost_system.so;
${Boost_LIBRARY_DIRS}/libboost_chrono.so;${Boost_LIBRARY_DIRS}/libboost_date_time.so;${Boost_LIBRARY_DIRS}/libboost_log.so;
${Boost_LIBRARY_DIRS}/libboost_log_setup.so;${Boost_LIBRARY_DIRS}/libboost_regex.so;${Boost_LIBRARY_DIRS}/libboost_serialization.so;
${Boost_LIBRARY_DIRS}/libboost_filesystem.so;${Boost_LIBRARY_DIRS}/libboost_locale.so;${Boost_LIBRARY_DIRS}/libboost_iostreams.so)
add_definitions(-DBOOST_ALL_DYN_LINK)
endif ()
include_directories(${Boost_INCLUDE_DIR})
endif ()

Expand Down
38 changes: 22 additions & 16 deletions src/log/Logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ logAdapter* logAdapter::alogInstance;
boost::mutex logAdapter::m_imtx;

logAdapter::~logAdapter() {
logging::core::get()->remove_all_sinks();
//only remove current sink
logging::core::get()->remove_sik(m_logSink);
m_logSink->stop();
m_logSink->flush();
}

logAdapter* logAdapter::getLogInstance() {
Expand All @@ -39,7 +42,8 @@ logAdapter* logAdapter::getLogInstance() {

logAdapter::logAdapter() : m_logLevel(eLOG_LEVEL_INFO) {
setLogDir();
string homeDir(UtilAll::getHomeDirectory());
//use current dir
string homeDir;
homeDir.append(m_log_dir);
m_logFile += homeDir;
std::string fileName = "rocketmq_client.log";
Expand All @@ -65,31 +69,32 @@ logAdapter::logAdapter() : m_logLevel(eLOG_LEVEL_INFO) {
void logAdapter::setLogLevelInner(elogLevel logLevel) {
switch (logLevel) {
case eLOG_LEVEL_FATAL:
logging::core::get()->set_filter(logging::trivial::severity >= logging::trivial::fatal);
//use current sink
m_logSink->set_filter(logging::trivial::severity >= logging::trivial::fatal);
break;
case eLOG_LEVEL_ERROR:
logging::core::get()->set_filter(logging::trivial::severity >= logging::trivial::error);

//use current sink
m_logSink->set_filter(logging::trivial::severity >= logging::trivial::error);
break;
case eLOG_LEVEL_WARN:
logging::core::get()->set_filter(logging::trivial::severity >= logging::trivial::warning);

//use current sink
m_logSink->set_filter(logging::trivial::severity >= logging::trivial::warning);
break;
case eLOG_LEVEL_INFO:
logging::core::get()->set_filter(logging::trivial::severity >= logging::trivial::info);

//use current sink
m_logSink->set_filter(logging::trivial::severity >= logging::trivial::info);
break;
case eLOG_LEVEL_DEBUG:
logging::core::get()->set_filter(logging::trivial::severity >= logging::trivial::debug);

//use current sink
m_logSink->set_filter(logging::trivial::severity >= logging::trivial::debug);
break;
case eLOG_LEVEL_TRACE:
logging::core::get()->set_filter(logging::trivial::severity >= logging::trivial::trace);

//use current sink
m_logSink->set_filter(logging::trivial::severity >= logging::trivial::trace);
break;
default:
logging::core::get()->set_filter(logging::trivial::severity >= logging::trivial::info);

//use current sink
m_logSink->set_filter(logging::trivial::severity >= logging::trivial::info);
break;
}
}
Expand Down Expand Up @@ -117,7 +122,8 @@ void logAdapter::setLogDir() {
}

void logAdapter::setLogFileNumAndSize(int logNum, int sizeOfPerFile) {
string homeDir(UtilAll::getHomeDirectory());
//use current dir
string homeDir;
homeDir.append(m_log_dir);
m_logSink->locked_backend()->set_file_collector(sinks::file::make_collector(
keywords::target = homeDir, keywords::max_size = logNum * sizeOfPerFile * 1024 * 1024));
Expand Down