Logger.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * Copyright (c) 2002-2009 Moxie Marlinspike
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License as
  6. * published by the Free Software Foundation; either version 3 of the
  7. * License, or (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  17. * USA
  18. */
  19. #include "Logger.hpp"
  20. #include <log4cpp/Category.hh>
  21. #include <log4cpp/FileAppender.hh>
  22. #include <log4cpp/BasicLayout.hh>
  23. void Logger::initialize(std::string &path, bool postOnly) {
  24. log4cpp::Appender* app = new log4cpp::FileAppender("FileAppender", path);
  25. log4cpp::Layout* layout = new log4cpp::BasicLayout();
  26. app->setLayout(layout);
  27. log4cpp::Category &sslsniff = log4cpp::Category::getInstance("sslsniff");
  28. sslsniff.setAdditivity(false);
  29. sslsniff.setAppender(app);
  30. if (postOnly) sslsniff.setPriority(log4cpp::Priority::INFO);
  31. else sslsniff.setPriority(log4cpp::Priority::DEBUG);
  32. }
  33. void Logger::logFromServer(std::string &name, char *buf, int len) {
  34. std::string data(buf, len);
  35. std::string message = "Read from Server (";
  36. message.append(name);
  37. message.append(") :\n");
  38. message.append(data);
  39. log4cpp::Category::getInstance("sslsniff").debug(message);
  40. }
  41. void Logger::logFromClient(std::string &name, char* buf, int len) {
  42. std::string data(buf, len);
  43. std::string message = "Read from Client (";
  44. message.append(name);
  45. message.append(") :\n");
  46. message.append(data);
  47. log4cpp::Category::getInstance("sslsniff").debug(message);
  48. }
  49. void Logger::logFromClient(std::string &name, HttpHeaders &headers) {
  50. std::string message = "Got POST (";
  51. message.append(name);
  52. message.append(") :\n");
  53. message.append(headers.getPostData());
  54. log4cpp::Category::getInstance("sslsniff").info(message);
  55. }
  56. void Logger::logUpdateRequest(std::string &product, std::string &version,
  57. std::string &buildId, std::string &buildTarget,
  58. std::string &locale, std::string &channel,
  59. std::string &filename)
  60. {
  61. std::string message =
  62. "Got update request:\n Product: " + product + "\n" +
  63. "Version: " + version + "\n" +
  64. "ID: " + buildId + "\n" +
  65. "Target: " + buildTarget + "\n" +
  66. "Locale: " + locale + "\n" +
  67. "Channel: " + channel + "\n" +
  68. "Filename: " + filename;
  69. log4cpp::Category::getInstance("sslsniff").info(message);
  70. }
  71. void Logger::logError(std::string error) {
  72. log4cpp::Category::getInstance("sslsniff").debug(error);
  73. }
  74. void Logger::logAddonUpdate(std::string &appId) {
  75. log4cpp::Category::getInstance("sslsniff").info("Updating Firefox Extension: " + appId);
  76. }
  77. void Logger::logInit(std::string message) {
  78. log4cpp::Category::getInstance("sslsniff").info(message);
  79. }