summaryrefslogtreecommitdiffstats
path: root/lib/Plugins/Logger.cpp
blob: 68734df4485875f26a3f7416ffd38e3c1b25e753 (plain)
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
98
99
100
101
/*
    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 "Logger.h"
#include <fstream>

CLogger::CLogger() :
    m_sLogPath("/tmp/CCLogger"),
    m_bAppendLogs(true)
{}

void CLogger::SetSettings(const map_settings_t& pSettings)
{
    if (pSettings.find("LogPath")!= pSettings.end())
    {
        m_sLogPath = pSettings.find("LogPath")->second;
    }
    if (pSettings.find("AppendLogs")!= pSettings.end())
    {
        m_bAppendLogs = pSettings.find("AppendLogs")->second == "yes";
    }
}

void CLogger::Report(const crash_report_t& pReport)
{
    std::ofstream fOut;
    if (m_bAppendLogs)
    {
        fOut.open(m_sLogPath.c_str(), std::ios::app);
    }
    else
    {
        fOut.open(m_sLogPath.c_str());
    }
    if (fOut.is_open())
    {
         fOut << "Common information" << std::endl;
         fOut << "==================" << std::endl << std::endl;
         fOut << "Architecture" << std::endl;
         fOut << "------------" << std::endl;
         fOut << pReport.m_sArchitecture << std::endl << std::endl;
         fOut << "Kernel version" << std::endl;
         fOut << "--------------" << std::endl;
         fOut << pReport.m_sKernel << std::endl << std::endl;
         fOut << "Package" << std::endl;
         fOut << "-------" << std::endl;
         fOut << pReport.m_sPackage << std::endl << std::endl;
         fOut << "Executable" << std::endl;
         fOut << "----------" << std::endl;
         fOut << pReport.m_sExecutable << std::endl << std::endl;
         fOut << "CmdLine" << std::endl;
         fOut << "----------" << std::endl;
         fOut << pReport.m_sCmdLine << std::endl << std::endl;
         fOut << "Created report" << std::endl;
         fOut << "==============" << std::endl;
         fOut << "Text reports" << std::endl;
         fOut << "==============" << std::endl;
         if (pReport.m_sTextData1 != "")
         {
             fOut << "Text Data 1" << std::endl;
             fOut << "-----------" << std::endl;
             fOut << pReport.m_sTextData1 << std::endl << std::endl;
         }
         if (pReport.m_sTextData2 != "")
         {
             fOut << "Text Data 2" << std::endl;
             fOut << "-----------" << std::endl;
             fOut << pReport.m_sTextData2 << std::endl << std::endl;
         }
         fOut << "Binary reports" << std::endl;
         fOut << "==============" << std::endl;
         if (pReport.m_sBinaryData1 != "")
         {
             fOut << "1. " <<  pReport.m_sBinaryData1 << std::endl;
         }
         if (pReport.m_sBinaryData2 != "")
         {
             fOut << "2. " <<  pReport.m_sBinaryData2 << std::endl;
         }
         fOut << std::endl;
         fOut.close();
    }
}