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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
/*
Logger.cpp - it simple writes report to specific file
Copyright (C) 2009 Zdenek Prikryl (zprikryl@redhat.com)
Copyright (C) 2009 RedHat inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <fstream>
#include <sstream>
#include "abrtlib.h"
#include "Logger.h"
#include "DebugDump.h"
#include "CommLayerInner.h"
#include "ABRTException.h"
CLogger::CLogger() :
m_sLogPath("/var/log/abrt-logger"),
m_bAppendLogs(true)
{}
void CLogger::SetSettings(const map_plugin_settings_t& pSettings)
{
m_pSettings = pSettings;
map_plugin_settings_t::const_iterator end = pSettings.end();
map_plugin_settings_t::const_iterator it;
it = pSettings.find("LogPath");
if (it != end)
{
m_sLogPath = it->second;
}
it = pSettings.find("AppendLogs");
if (it != end)
{
m_bAppendLogs = string_to_bool(it->second.c_str());
}
}
//ok to delete?
//const map_plugin_settings_t& CLogger::GetSettings()
//{
// m_pSettings["LogPath"] = m_sLogPath;
// m_pSettings["AppendLogs"] = m_bAppendLogs ? "yes" : "no";
//
// return m_pSettings;
//}
std::string CLogger::Report(const map_crash_report_t& pCrashReport,
const map_plugin_settings_t& pSettings, const std::string& pArgs)
{
update_client(_("Creating a report..."));
std::string description = make_description_logger(pCrashReport);
description += "\n\n\n";
FILE *fOut;
if (m_bAppendLogs)
{
fOut = fopen(m_sLogPath.c_str(), "a");
}
else
{
fOut = fopen(m_sLogPath.c_str(), "w");
}
if (fOut)
{
fputs(description.c_str(), fOut);
fclose(fOut);
return "file://" + m_sLogPath;
}
throw CABRTException(EXCEP_PLUGIN, "CLogger::Report(): Cannot open file: " + m_sLogPath);
}
PLUGIN_INFO(REPORTER,
CLogger,
"Logger",
"0.0.1",
"Write a report to a specific file",
"zprikryl@redhat.com",
"https://fedorahosted.org/abrt/wiki",
PLUGINS_LIB_DIR"/Logger.GTKBuilder");
|