Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(25)

Unified Diff: main.cc

Issue 6594001: entd: Factor out syslog_logger code and start using it (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/entd.git@master
Patch Set: respond to rginda Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: main.cc
diff --git a/main.cc b/main.cc
index 74dbd96e13e8c638788bf7f99929f8148fe4697f..520ec7c478eef7a4c6b1bc52abf60dfcebe7f041 100644
--- a/main.cc
+++ b/main.cc
@@ -3,29 +3,12 @@
// found in the LICENSE file.
#include <stdio.h>
-#include <syslog.h>
-
-// syslog.h and base/logging.h both try to #define LOG_INFO and LOG_WARNING.
-// We need to #undef at least these two before including base/logging.h. The
-// others are included to be consistent.
-namespace {
-const int kSyslogInfo = LOG_INFO;
-const int kSyslogWarning = LOG_WARNING;
-const int kSyslogError = LOG_ERR;
-const int kSyslogCritical = LOG_CRIT;
-
-#undef LOG_INFO
-#undef LOG_WARNING
-#undef LOG_ERR
-#undef LOG_INFO
-} // namespace
-
#include <iostream>
#include <string>
#include <base/command_line.h>
#include <base/file_util.h>
-#include <base/logging.h>
+#include <chromeos/syslog_logging.h>
#include "entd/entd.h"
#include "entd/extensions.h"
@@ -75,41 +58,6 @@ static const char *kCallbackOrigin = "callback-origin";
} // namespace switches
-bool handle_message(int severity, const std::string &message) {
- switch (severity) {
- case logging::LOG_INFO:
- severity = kSyslogInfo;
- break;
-
- case logging::LOG_WARNING:
- severity = kSyslogWarning;
- break;
-
- case logging::LOG_ERROR:
- case logging::LOG_ERROR_REPORT:
- severity = kSyslogError;
- break;
-
- case logging::LOG_FATAL:
- severity = kSyslogCritical;
- break;
- }
-
- // The first "] " should be the end of the header added by the logging
- // code. The meat of the message is two characters after that.
- size_t pos = message.find("] ");
- if (pos != std::string::npos && message.length() > pos + 2) {
- pos += 2;
- } else {
- pos = 0;
- }
-
- const char* str = message.c_str() + pos;
-
- syslog(severity, "%s", str);
- return false;
-}
-
// Return values:
// 0: Entd completed successfully and should not be restarted.
// 1: Entd encountered a failure, but will probably fail again if restarted,
@@ -124,17 +72,15 @@ int main(int argc, char** argv) {
CommandLine::Init(argc, argv);
CommandLine* cl = CommandLine::ForCurrentProcess();
-
- logging::InitLogging("/dev/null", logging::LOG_ONLY_TO_SYSTEM_DEBUG_LOG,
- logging::DONT_LOCK_LOG_FILE,
- logging::APPEND_TO_OLD_LOG_FILE);
+ int log_flags = chromeos::kLogToStderr;
if (cl->HasSwitch(switches::kEnableSyslog) ||
(!isatty(STDOUT_FILENO) && !cl->HasSwitch(switches::kDisableSyslog))) {
// If syslog was explicitly enabled, or stdout is not a tty and syslog
// was not explicitly disabled, then send all LOG(...) messages to syslog.
- logging::SetLogMessageHandler(handle_message);
+ log_flags |= chromeos::kLogToSyslog;
}
+ chromeos::InitLog(log_flags);
rginda 2011/03/02 19:26:38 nit: newline before this please.
LOG(INFO) << "Starting entd";
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698