-
Notifications
You must be signed in to change notification settings - Fork 118
/
Logger.cpp
95 lines (79 loc) · 3.22 KB
/
Logger.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
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
/*
* Copyright (c) 2002-2009 Moxie Marlinspike
*
* 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 3 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*/
#include "Logger.hpp"
#include <log4cpp/Category.hh>
#include <log4cpp/FileAppender.hh>
#include <log4cpp/BasicLayout.hh>
void Logger::initialize(std::string &path, bool postOnly) {
log4cpp::Appender* app = new log4cpp::FileAppender("FileAppender", path);
log4cpp::Layout* layout = new log4cpp::BasicLayout();
app->setLayout(layout);
log4cpp::Category &sslsniff = log4cpp::Category::getInstance("sslsniff");
sslsniff.setAdditivity(false);
sslsniff.setAppender(app);
if (postOnly) sslsniff.setPriority(log4cpp::Priority::INFO);
else sslsniff.setPriority(log4cpp::Priority::DEBUG);
}
void Logger::logFromServer(std::string &name, char *buf, int len) {
std::string data(buf, len);
std::string message = "Read from Server (";
message.append(name);
message.append(") :\n");
message.append(data);
log4cpp::Category::getInstance("sslsniff").debug(message);
}
void Logger::logFromClient(std::string &name, char* buf, int len) {
std::string data(buf, len);
std::string message = "Read from Client (";
message.append(name);
message.append(") :\n");
message.append(data);
log4cpp::Category::getInstance("sslsniff").debug(message);
}
void Logger::logFromClient(std::string &name, HttpHeaders &headers) {
std::string message = "Got POST (";
message.append(name);
message.append(") :\n");
message.append(headers.getPostData());
log4cpp::Category::getInstance("sslsniff").info(message);
}
void Logger::logUpdateRequest(std::string &product, std::string &version,
std::string &buildId, std::string &buildTarget,
std::string &locale, std::string &channel,
std::string &filename)
{
std::string message =
"Got update request:\n Product: " + product + "\n" +
"Version: " + version + "\n" +
"ID: " + buildId + "\n" +
"Target: " + buildTarget + "\n" +
"Locale: " + locale + "\n" +
"Channel: " + channel + "\n" +
"Filename: " + filename;
log4cpp::Category::getInstance("sslsniff").info(message);
}
void Logger::logError(std::string error) {
log4cpp::Category::getInstance("sslsniff").debug(error);
}
void Logger::logAddonUpdate(std::string &appId) {
log4cpp::Category::getInstance("sslsniff").info("Updating Firefox Extension: " + appId);
}
void Logger::logInit(std::string message) {
log4cpp::Category::getInstance("sslsniff").info(message);
}