Logger.h

#ifndef AURORA_LOGGER_H
#define AURORA_LOGGER_H

#include "Common.h"

#include <log4cplus/logger.h>

#include <string>

namespace aurora
{
    class Logger : noncopyable
    {
        static constexpr int LOG_BUFFER_SIZE = 1024;
    public:
        static void
        Start(const std::string &alias, const std::string &fileName = "", unsigned int threadNum = 1,
              unsigned int logLevel = 0);

        static void Info(const char *fomart, ...);

        static void Debug(const char *fomart, ...);

        static void Warn(const char *fomart, ...);

        static void Error(const char *fomart, ...);

        static void Stop();

    private:
        DISALLOW_COPY_AND_ASSIGN(Logger);

        static log4cplus::Logger m_logger;
    };
}
using namespace aurora;
#endif //AURORA_LOGGER_H

Logger.cpp

#include "Logger.h"

#include <log4cplus/consoleappender.h>
#include <log4cplus/fileappender.h>
#include <log4cplus/initializer.h>

#include <cstdarg>

using namespace aurora;
using namespace log4cplus;
using namespace log4cplus::helpers;

log4cplus::Logger aurora::Logger::m_logger;

#define DO_LOGGER(log_level, format)               \
    if (m_logger.isEnabledFor(log_level))          \
    {                                              \
        va_list args;                              \
        va_start(args, format);                    \
        char buf[LOG_BUFFER_SIZE] = {0};           \
        vsnprintf(buf, sizeof(buf), format, args); \
        va_end(args);                              \
        m_logger.forcedLog(log_level, buf);        \
    }

void aurora::Logger::Start(const std::string &alias, const std::string &fileName, unsigned int threadNum,
                           unsigned int logLevel)
{
    static Initializer initializer;
//    helpers::LogLog::getLogLog()->setInternalDebugging(true);
    std::string pattern = "%D{%y-%m-%d %H:%M:%S} [%c:%p] %m%n";
    m_logger = log4cplus::Logger::getInstance(alias);
    m_logger.setLogLevel(log_level * 10000);
    if (!file_name.empty())
    {
        SharedAppenderPtr app(new DailyRollingFileAppender(file_name, DAILY, true, 999, true, false, "%Y-%m-%d.log"));
        app->setName(LOG4CPLUS_TEXT("DailyFile"));
        app->setLayout(std::make_unique<PatternLayout>(pattern));
        m_logger.addAppender(app);
    }

//    SharedAppenderPtr time(
//            new TimeBasedRollingFileAppender("", "./log/%d/%d{yyyy-MM-dd-HH-mm}.log", 999, false, true, true,
//                                             false));
    SharedAppenderPtr time(
            new TimeBasedRollingFileAppender("", "./log/%d{yyyy-MM-dd}.log", 999, false, true, true,
                                             false));
    time->setLayout(std::make_unique<PatternLayout>(pattern));
    time->setName(LOG4CPLUS_TEXT("TimeFile"));
    m_logger.addAppender(time);

    SharedAppenderPtr console(new ConsoleAppender());
    console->setLayout(std::make_unique<PatternLayout>(pattern));
    console->setName(LOG4CPLUS_TEXT("Console"));
    m_logger.addAppender(console);
    log4cplus::setThreadPoolSize(thread_num);
}

void aurora::Logger::Info(const char *fomart, ...)
{
    DO_LOGGER(INFO_LOG_LEVEL, fomart);
}

void aurora::Logger::Debug(const char *fomart, ...)
{
    DO_LOGGER(DEBUG_LOG_LEVEL, fomart);
}

void aurora::Logger::Warn(const char *fomart, ...)
{
    DO_LOGGER(WARN_LOG_LEVEL, fomart);
}

void aurora::Logger::Error(const char *fomart, ...)
{
    DO_LOGGER(ERROR_LOG_LEVEL, fomart);
}

void aurora::Logger::Stop()
{
    log4cplus::Logger::shutdown();
}

main.cpp

#include "Logger.h"

#include <chrono>
#include <iostream>

int main()
{
    Logger::Start("aurora");
    auto start = std::chrono::steady_clock::now();

    for (int i = 0; i < 10000; i++)
    {
        Logger::Info("INFO = %d", i);
        Logger::Debug("DEBUG = %d", i);
        Logger::Warn("WARN = %d", i);
        Logger::Error("ERROR = %d", i);
    }
    auto end = std::chrono::steady_clock::now();
    std::chrono::duration<double, std::milli> elapsed = end - start;
    std::cout << "time: " << elapsed.count() << "ms" << std::endl;

    Logger::Stop();
    return 0;
}