-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogtarget.cpp
57 lines (54 loc) · 1.2 KB
/
logtarget.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include "logtarget.h"
LogTarget::LogTarget(const QString &type/* err, syslog, file, pipe */, const QString ¶m) :
m_type(TypeNone)
{
if (type == "err")
{
m_file = new QFile();
if(m_file->open(2, QIODevice::Text | QIODevice::Unbuffered | QIODevice::WriteOnly))
m_type = TypeErr;
else
delete m_file;
}
else if (type == "file")
{
m_file = new QFile(param);
if(m_file->open(QIODevice::Text | QIODevice::Unbuffered | QIODevice::ReadWrite | QIODevice::Append))
m_type = TypeFile;
else
delete m_file;
}
else if (type == "pipe")
{
m_file = new QFile(param);
if(m_file->open(QIODevice::Text | QIODevice::Unbuffered | QIODevice::WriteOnly | QIODevice::Truncate))
m_type = TypePipe;
else
delete m_file;
}
}
LogTarget::~LogTarget()
{
switch (m_type)
{
case TypeErr:
case TypeFile:
case TypePipe:
m_file->close();
delete m_file;
break;
default:;
}
}
void LogTarget::send(const QString &source, Logger::Level level, const QString &msg)
{
switch (m_type)
{
case TypeErr:
case TypeFile:
case TypePipe:
m_file->write(/* TODO: source, level*/(QDateTime::currentDateTime().toString("[yyyy-MM-dd hh:mm:ss.zzz] ") + msg + "\n").toUtf8());
break;
default:;
}
}