#include "logger.h"
#include <QDateTime>
#include <QDir>
#include <QFile>
#include <QTextStream>
#include <QDebug>

#if 0
#include <spdlog/spdlog.h>
#endif

namespace common {

#if 0
Logger::Logger(QObject *parent) : QObject(parent) {}

void Logger::outputMessage(QtMsgType type,
                           const QMessageLogContext &context,
                           const QString &msg) {
    Q_UNUSED(context)
    switch (type) {
    case QtDebugMsg: {
      logger()->debug(msg.toStdString());
      break;
    }
    case QtWarningMsg: {
      logger()->warn(msg.toStdString());
      break;
    }
    case QtCriticalMsg: {
      logger()->critical(msg.toStdString());
      break;
    }
    case QtInfoMsg: {
      logger()->info(msg.toStdString());
      break;
    }
    default:
      break;
    }
    logger()->flush();
}

std::shared_ptr<spdlog::logger> Logger::logger() {
    QString logFileName =
        qgetenv("HOME") + "/.cache/kylin/ukui-tablet-desktop/daily.txt";
    static auto logger = spdlog::daily_logger_mt(
        "daily_logger", logFileName.toStdString().c_str(), 2, 30);
    logger->set_level(spdlog::level::debug);
    return logger;
}
#endif

void QmlLogger::debug(const QString &msg)
{
    qDebug() << msg;
}

void QmlLogger::info(const QString &msg)
{
    qInfo() << msg;
}

void QmlLogger::warning(const QString &msg)
{
    qWarning() << msg;
}

void QmlLogger::critical(const QString &msg)
{
    qCritical() << msg;
}

}  // namespace utils
