pastarmovj | 114af1b | 2016-09-20 23:58:13 +0900 | [diff] [blame] | 1 | // Copyright 2016 The Chromium 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 | #ifndef BASE_SYSLOG_LOGGING_H_ |
| 6 | #define BASE_SYSLOG_LOGGING_H_ |
| 7 | |
proberge | d3fae64 | 2017-06-23 23:29:01 +0900 | [diff] [blame] | 8 | #include <iosfwd> |
| 9 | |
pastarmovj | 114af1b | 2016-09-20 23:58:13 +0900 | [diff] [blame] | 10 | #include "base/logging.h" |
proberge | d3fae64 | 2017-06-23 23:29:01 +0900 | [diff] [blame] | 11 | #include "build/build_config.h" |
pastarmovj | 114af1b | 2016-09-20 23:58:13 +0900 | [diff] [blame] | 12 | |
| 13 | namespace logging { |
| 14 | |
| 15 | // Keep in mind that the syslog is always active regardless of the logging level |
| 16 | // and applied flags. Use only for important information that a system |
| 17 | // administrator might need to maintain the browser installation. |
| 18 | #define SYSLOG_STREAM(severity) \ |
| 19 | COMPACT_GOOGLE_LOG_EX_ ## severity(EventLogMessage).stream() |
| 20 | #define SYSLOG(severity) \ |
| 21 | SYSLOG_STREAM(severity) |
| 22 | |
proberge | d3fae64 | 2017-06-23 23:29:01 +0900 | [diff] [blame] | 23 | #if defined(OS_WIN) |
| 24 | // Sets the name, category and event id of the event source for logging to the |
| 25 | // Windows Event Log. Call this function once before using the SYSLOG macro or |
| 26 | // otherwise it will behave as a regular LOG macro. |
| 27 | void BASE_EXPORT SetEventSource(const std::string& name, |
| 28 | uint16_t category, |
| 29 | uint32_t event_id); |
| 30 | #endif // defined(OS_WIN) |
pastarmovj | 89e02ea | 2016-12-08 02:38:52 +0900 | [diff] [blame] | 31 | |
pastarmovj | 114af1b | 2016-09-20 23:58:13 +0900 | [diff] [blame] | 32 | // Creates a formatted message on the system event log. That would be the |
| 33 | // Application Event log on Windows and the messages log file on POSIX systems. |
| 34 | class BASE_EXPORT EventLogMessage { |
| 35 | public: |
| 36 | EventLogMessage(const char* file, int line, LogSeverity severity); |
| 37 | |
| 38 | ~EventLogMessage(); |
| 39 | |
| 40 | std::ostream& stream() { return log_message_.stream(); } |
| 41 | |
| 42 | private: |
| 43 | LogMessage log_message_; |
| 44 | |
| 45 | DISALLOW_COPY_AND_ASSIGN(EventLogMessage); |
| 46 | }; |
| 47 | |
| 48 | } // namespace logging |
| 49 | |
| 50 | #endif // BASE_SYSLOG_LOGGING_H_ |