最近看一个音乐播放器的源码的时候,看了一下他的日志输出实现,虽然代码量不多,但是功能倒是挺齐全,有点不足的是里面只是实现了单文件输出。
这里面理解起来没有什么掌握,我只是加了简单的注释
#ifndef MUSICLOGGER_H
#define MUSICLOGGER_H
/* =================================================
* This file is part of the TTK Music Player project
* Copyright (c) 2014 - 2016 Greedysky Studio
* All rights reserved!
* Redistribution and use of the source code or any derivative
* works are strictly forbiden.
=================================================*/
#include <QFile>
#include <QTextStream>
#include <QDateTime>
#include "musicglobaldefine.h"
#define CURRENTTIME QTime::currentTime().toString("hh:mm:ss:zzz")
#define CURRENTDATE QDate::currentDate().toString("yyyy-MM-dd")
#define LOG_END QString("log::npos")
#define M_LOGGER (*MusicLogger::createInstance())
#define M_MESSAGE(str, msg) \
{ \
M_LOGGER.setLevel(msg); \
M_LOGGER << str << LOG_END;\
}
#ifdef MUSIC_DEBUG
#define