<commit_before>// -------------------------------------------------------------------------
//    @FileName      :    NFCLogModule.cpp
//    @Author           :    LvSheng.Huang
//    @Date             :    2012-12-15
//    @Module           :    NFCLogModule
//    @Desc             :
// -------------------------------------------------------------------------

#define GLOG_NO_ABBREVIATED_SEVERITIES
#include "glog/logging.h"
#include <time.h>
#include "NFStackWalker.h"
#include "NFCLogModule.h"
#include <boost/filesystem.hpp>
#include "NFComm/NFPluginModule/NFIActorManager.h"
#include "NFComm/NFPluginModule/NFIActor.h"

NFCLogModule::NFCLogModule(NFIPluginManager* p)
{
    pPluginManager = p;
    
    //m_pFd = NULL;
}

bool NFCLogModule::Init()
{
#ifdef NF_DYNAMIC_PLUGIN

    NFIActor* pActor = (NFIActor*)(pPluginManager);
    if(pActor->GetActorID() == NFIActorManager::EACTOR_MAIN)
    {
#endif

        char szName[MAX_PATH] = {0};

        GetConsoleTitle(szName, MAX_PATH);
        google::InitGoogleLogging(szName);

        std::string strPath = std::string("./log/") + szName;
        if (!boost::filesystem::exists(strPath))
        {
            boost::filesystem::create_directories(strPath);
        }

#ifdef NF_DEBUG_MODE
        google::SetStderrLogging(google::GLOG_INFO); //ü google::INFO ־ͬʱĻ
#else
        google::SetStderrLogging(google::GLOG_FATAL);//ü google::FATAL ־ͬʱĻ
#endif

        FLAGS_colorlogtostderr = true;    //Ļ־ʾӦɫ
        FLAGS_servitysinglelog = true;

        google::SetLogDestination(google::GLOG_FATAL, std::string(strPath + "/log_fatal_").c_str());
        google::SetLogDestination(google::GLOG_ERROR, std::string(strPath + "/log_error_").c_str());      // google::error ־洢·ļǰ׺
        google::SetLogDestination(google::GLOG_WARNING, std::string(strPath + "/log_warning_").c_str());  // google::WARNING ־洢·ļǰ׺
        google::SetLogDestination(google::GLOG_INFO, std::string(strPath + "/log_Info_").c_str());        // google::INFO ־洢·ļǰ׺

        FLAGS_logbufsecs = 0;                       //־ĬΪ30룬˴Ϊ
        FLAGS_max_log_size = 100;                   //־СΪ 100MB
        FLAGS_stop_logging_if_full_disk = true;     //̱дʱֹͣ־
       
#ifdef NF_DYNAMIC_PLUGIN
    }
#endif

    //google::SetLogFilenameExtension("91_");   //ļչƽ̨ҪֵϢ
    //google::InstallFailureSignalHandler();    //׽ core dumped
    //google::InstallFailureWriter(&Log);       //Ĭϲ׽ SIGSEGV źϢ stderrͨķԶʽ
    
    return true;
}

bool NFCLogModule::Shut()
{
#ifdef NF_DYNAMIC_PLUGIN
    NFIActor* pActor = (NFIActor*)(pPluginManager);
    if(pActor->GetActorID() == NFIActorManager::EACTOR_MAIN)
    {
        google::ShutdownGoogleLogging();
    }
#else
    google::ShutdownGoogleLogging();
#endif

    return true;
}

bool NFCLogModule::BeforeShut()
{
    return true;

}

bool NFCLogModule::AfterInit()
{
    return true;

}

bool NFCLogModule::Execute(const float fLasFrametime, const float fStartedTime)
{
    return true;

}

bool NFCLogModule::Log(const NF_LOG_LEVEL nll, const char* format, ...)
{
    char szBuffer[1024 * 10] = {0};

    va_list args;
    va_start(args, format);
    _vsnprintf(szBuffer, sizeof(szBuffer) - 1, format, args);
    va_end(args);

#ifdef NF_DYNAMIC_PLUGIN
    NFIActor* pActor = (NFIActor*)(pPluginManager);
    if(!pActor->GetActorID() == NFIActorManager::EACTOR_MAIN)
    {
        NFIActorMessage message;
        message.eType = NFIActorMessage::EACTOR_LOG_MSG;
        message.data = szBuffer;

        const Theron::Address address = pActor->GetActorManager()->GetAddress(NFIActorManager::EACTOR_MAIN);
        if (address != Theron::Address::Null())
        {
            pActor->GetFramework().Send(message, pActor->GetAddress(), address);
        }

        return true;
    }
#endif

    switch (nll)
    {
        case NFILogModule::NLL_INFO_NORMAL:
            LOG(INFO) << szBuffer;
            break;
        case NFILogModule::NLL_WARING_NORMAL:
            LOG(WARNING) << szBuffer;
            break;
        case NFILogModule::NLL_ERROR_NORMAL:
            {
                LOG(ERROR) << szBuffer;
                LogStack();<commit_msg>remove dump when log error info<commit_after>// -------------------------------------------------------------------------
//    @FileName      :    NFCLogModule.cpp
//    @Author           :    LvSheng.Huang
//    @Date             :    2012-12-15
//    @Module           :    NFCLogModule
//    @Desc             :
// -------------------------------------------------------------------------

#define GLOG_NO_ABBREVIATED_SEVERITIES
#include "glog/logging.h"
#include <time.h>
#include "NFStackWalker.h"
#include "NFCLogModule.h"
#include <boost/filesystem.hpp>
#include "NFComm/NFPluginModule/NFIActorManager.h"
#include "NFComm/NFPluginModule/NFIActor.h"

NFCLogModule::NFCLogModule(NFIPluginManager* p)
{
    pPluginManager = p;
    
    //m_pFd = NULL;
}

bool NFCLogModule::Init()
{
#ifdef NF_DYNAMIC_PLUGIN

    NFIActor* pActor = (NFIActor*)(pPluginManager);
    if(pActor->GetActorID() == NFIActorManager::EACTOR_MAIN)
    {
#endif

        char szName[MAX_PATH] = {0};

        GetConsoleTitle(szName, MAX_PATH);
        google::InitGoogleLogging(szName);

        std::string strPath = std::string("./log/") + szName;
        if (!boost::filesystem::exists(strPath))
        {
            boost::filesystem::create_directories(strPath);
        }

#ifdef NF_DEBUG_MODE
        google::SetStderrLogging(google::GLOG_INFO); //ü google::INFO ־ͬʱĻ
#else
        google::SetStderrLogging(google::GLOG_FATAL);//ü google::FATAL ־ͬʱĻ
#endif

        FLAGS_colorlogtostderr = true;    //Ļ־ʾӦɫ
        FLAGS_servitysinglelog = true;

        google::SetLogDestination(google::GLOG_FATAL, std::string(strPath + "/log_fatal_").c_str());
        google::SetLogDestination(google::GLOG_ERROR, std::string(strPath + "/log_error_").c_str());      // google::error ־洢·ļǰ׺
        google::SetLogDestination(google::GLOG_WARNING, std::string(strPath + "/log_warning_").c_str());  // google::WARNING ־洢·ļǰ׺
        google::SetLogDestination(google::GLOG_INFO, std::string(strPath + "/log_Info_").c_str());        // google::INFO ־洢·ļǰ׺

        FLAGS_logbufsecs = 0;                       //־ĬΪ30룬˴Ϊ
        FLAGS_max_log_size = 100;                   //־СΪ 100MB
        FLAGS_stop_logging_if_full_disk = true;     //̱дʱֹͣ־
       
#ifdef NF_DYNAMIC_PLUGIN
    }
#endif

    //google::SetLogFilenameExtension("91_");   //ļչƽ̨ҪֵϢ
    //google::InstallFailureSignalHandler();    //׽ core dumped
    //google::InstallFailureWriter(&Log);       //Ĭϲ׽ SIGSEGV źϢ stderrͨķԶʽ
    
    return true;
}

bool NFCLogModule::Shut()
{
#ifdef NF_DYNAMIC_PLUGIN
    NFIActor* pActor = (NFIActor*)(pPluginManager);
    if(pActor->GetActorID() == NFIActorManager::EACTOR_MAIN)
    {
        google::ShutdownGoogleLogging();
    }
#else
    google::ShutdownGoogleLogging();
#endif

    return true;
}

bool NFCLogModule::BeforeShut()
{
    return true;

}

bool NFCLogModule::AfterInit()
{
    return true;

}

bool NFCLogModule::Execute(const float fLasFrametime, const float fStartedTime)
{
    return true;

}

bool NFCLogModule::Log(const NF_LOG_LEVEL nll, const char* format, ...)
{
    char szBuffer[1024 * 10] = {0};

    va_list args;
    va_start(args, format);
    _vsnprintf(szBuffer, sizeof(szBuffer) - 1, format, args);
    va_end(args);

#ifdef NF_DYNAMIC_PLUGIN
    NFIActor* pActor = (NFIActor*)(pPluginManager);
    if(!pActor->GetActorID() == NFIActorManager::EACTOR_MAIN)
    {
        NFIActorMessage message;
        message.eType = NFIActorMessage::EACTOR_LOG_MSG;
        message.data = szBuffer;

        const Theron::Address address = pActor->GetActorManager()->GetAddress(NFIActorManager::EACTOR_MAIN);
        if (address != Theron::Address::Null())
        {
            pActor->GetFramework().Send(message, pActor->GetAddress(), address);
        }

        return true;
    }
#endif

    switch (nll)
    {
        case NFILogModule::NLL_INFO_NORMAL:
            LOG(INFO) << szBuffer;
            break;
        case NFILogModule::NLL_WARING_NORMAL:
            LOG(WARNING) << szBuffer;
            break;
        case NFILogModule::NLL_ERROR_NORMAL:
            {
                LOG(ERROR) << szBuffer;
                //LogStack();
{'fraction_non_alphanumeric': 0.16803874092009685, 'fraction_numerical': 0.006779661016949152, 'mean_word_length': 2.479780960404381, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4665029', 'n_tokens_mistral': 2953, 'n_tokens_neox': 2862, 'n_words': 426}