| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "crash-reporter/system_logging.h" | |
| 6 | |
| 7 #include <syslog.h> | |
| 8 | |
| 9 #include "base/stringprintf.h" | |
| 10 | |
| 11 std::string SystemLoggingImpl::identity_; | |
| 12 | |
| 13 SystemLoggingImpl::SystemLoggingImpl() : is_accumulating_(false) { | |
| 14 } | |
| 15 | |
| 16 SystemLoggingImpl::~SystemLoggingImpl() { | |
| 17 } | |
| 18 | |
| 19 void SystemLoggingImpl::Initialize(const char *ident) { | |
| 20 // Man page does not specify if openlog copies its string or assumes | |
| 21 // the pointer is always valid, so make its scope global. | |
| 22 identity_ = ident; | |
| 23 openlog(identity_.c_str(), LOG_PID, LOG_USER); | |
| 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 | |
| 36 void SystemLoggingImpl::LogInfo(const char *format, ...) { | |
| 37 va_list vl; | |
| 38 va_start(vl, format); | |
| 39 LogWithLevel(LOG_INFO, format, vl); | |
| 40 va_end(vl); | |
| 41 } | |
| 42 | |
| 43 void SystemLoggingImpl::LogWarning(const char *format, ...) { | |
| 44 va_list vl; | |
| 45 va_start(vl, format); | |
| 46 LogWithLevel(LOG_WARNING, format, vl); | |
| 47 va_end(vl); | |
| 48 } | |
| 49 | |
| 50 void SystemLoggingImpl::LogError(const char *format, ...) { | |
| 51 va_list vl; | |
| 52 va_start(vl, format); | |
| 53 LogWithLevel(LOG_ERR, format, vl); | |
| 54 va_end(vl); | |
| 55 } | |
| OLD | NEW |