| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <stdarg.h> | 5 #include "crash-reporter/system_logging.h" |
| 6 |
| 6 #include <syslog.h> | 7 #include <syslog.h> |
| 7 | 8 |
| 8 #include "crash-reporter/system_logging.h" | 9 #include "base/stringprintf.h" |
| 9 | 10 |
| 10 std::string SystemLoggingImpl::identity_; | 11 std::string SystemLoggingImpl::identity_; |
| 11 | 12 |
| 12 SystemLoggingImpl::SystemLoggingImpl() { | 13 SystemLoggingImpl::SystemLoggingImpl() : is_accumulating_(false) { |
| 13 } | 14 } |
| 14 | 15 |
| 15 SystemLoggingImpl::~SystemLoggingImpl() { | 16 SystemLoggingImpl::~SystemLoggingImpl() { |
| 16 } | 17 } |
| 17 | 18 |
| 18 void SystemLoggingImpl::Initialize(const char *ident) { | 19 void SystemLoggingImpl::Initialize(const char *ident) { |
| 19 // Man page does not specify if openlog copies its string or assumes | 20 // Man page does not specify if openlog copies its string or assumes |
| 20 // the pointer is always valid, so make its scope global. | 21 // the pointer is always valid, so make its scope global. |
| 21 identity_ = ident; | 22 identity_ = ident; |
| 22 openlog(identity_.c_str(), LOG_PID, LOG_USER); | 23 openlog(identity_.c_str(), LOG_PID, LOG_USER); |
| 23 } | 24 } |
| 24 | 25 |
| 26 void SystemLoggingImpl::LogWithLevel(int level, const char *format, |
| 27 va_list arg_list) { |
| 28 std::string message = StringPrintV(format, arg_list); |
| 29 syslog(level, "%s", message.c_str()); |
| 30 if (is_accumulating_) { |
| 31 accumulator_.append(message); |
| 32 accumulator_.push_back('\n'); |
| 33 } |
| 34 } |
| 35 |
| 25 void SystemLoggingImpl::LogInfo(const char *format, ...) { | 36 void SystemLoggingImpl::LogInfo(const char *format, ...) { |
| 26 va_list vl; | 37 va_list vl; |
| 27 va_start(vl, format); | 38 va_start(vl, format); |
| 28 vsyslog(LOG_INFO, format, vl); | 39 LogWithLevel(LOG_INFO, format, vl); |
| 29 va_end(vl); | 40 va_end(vl); |
| 30 } | 41 } |
| 31 | 42 |
| 32 void SystemLoggingImpl::LogWarning(const char *format, ...) { | 43 void SystemLoggingImpl::LogWarning(const char *format, ...) { |
| 33 va_list vl; | 44 va_list vl; |
| 34 va_start(vl, format); | 45 va_start(vl, format); |
| 35 vsyslog(LOG_WARNING, format, vl); | 46 LogWithLevel(LOG_WARNING, format, vl); |
| 36 va_end(vl); | 47 va_end(vl); |
| 37 } | 48 } |
| 38 | 49 |
| 39 void SystemLoggingImpl::LogError(const char *format, ...) { | 50 void SystemLoggingImpl::LogError(const char *format, ...) { |
| 40 va_list vl; | 51 va_list vl; |
| 41 va_start(vl, format); | 52 va_start(vl, format); |
| 42 vsyslog(LOG_ERR, format, vl); | 53 LogWithLevel(LOG_ERR, format, vl); |
| 43 va_end(vl); | 54 va_end(vl); |
| 44 } | 55 } |
| OLD | NEW |