hunting/utils/Log/src/LogEasylogging.cpp
2023-09-24 16:16:15 -07:00

102 lines
2.7 KiB
C++

/*
* Copyright (c) 2023 Fancy Code.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "ILog.h"
#include "LogEasylogging.h"
#include "easylogging++.h"
// #include <thread>
// #define ELPP_UNICODE // Define for easylogging
INITIALIZE_EASYLOGGINGPP // Init easylogging
// static bool initFlag = false; // Only used for init easyloggingpp
bool test = false;
LogEasylogging::LogEasylogging(const LogSetting *setting)
{
if (!setting)
{
return;
}
if (setting->fileName)
{
mFileName = setting->fileName;
}
if (setting->maxSize)
{
mMaxSize = setting->maxSize;
}
}
void LogEasylogging::Init(const enum LogInstance &log)
{
#if 0
el::Configurations conf("/home/xiaojiazhu/project/OS/OSThings/test/output_files/bin/default-logger.conf");
el::Loggers::reconfigureAllLoggers(conf);
#endif
// Set the log path.
if (mFileName.size() > 0)
{
el::Loggers::reconfigureAllLoggers(el::ConfigurationType::Filename, mFileName.c_str());
}
// Set the max size of log file.
// el::Loggers::reconfigureAllLoggers(el::ConfigurationType::MaxLogFileSize, "1048576");
if (mMaxSize.size() > 0)
{
el::Loggers::reconfigureAllLoggers(el::ConfigurationType::MaxLogFileSize, mMaxSize.c_str());
}
el::Loggers::reconfigureAllLoggers(el::ConfigurationType::Enabled, "true");
el::Loggers::reconfigureAllLoggers(el::ConfigurationType::ToFile, "true");
}
void LogEasylogging::UnInit(void)
{
el::Loggers::reconfigureAllLoggers(el::ConfigurationType::ToFile, "false");
el::Loggers::reconfigureAllLoggers(el::ConfigurationType::Enabled, "false");
}
// bool LogEasylogging::IsWorking()
// {
// return true;
// }
int LogEasylogging::Log(const char *buff)
{
// LOG(INFO) << buff;
return 0;
}
int LogEasylogging::InFo(const char *buff)
{
LOG(INFO) << buff;
return 0;
}
int LogEasylogging::Warning(const char *buff)
{
LOG(WARNING) << buff;
return 0;
}
int LogEasylogging::Error(const char *buff)
{
LOG(ERROR) << buff;
return 0;
}
int LogEasylogging::Debug(const char *buff)
{
LOG(DEBUG) << buff;
return 0;
}
int LogEasylogging::Trace(const char *buff)
{
LOG(TRACE) << buff;
return 0;
}