| Avi Drissman | e4622aa | 2022-09-08 20:36:06 | [diff] [blame] | 1 | // Copyright 2016 The Chromium Authors |
| pastarmovj | 89f7ee1 | 2016-09-20 14:58:13 | [diff] [blame] | 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 | fe47600 | 2017-06-23 14:29:01 | [diff] [blame] | 8 | #include <iosfwd> |
| 9 | |
| David Sanders | 6e70994 | 2022-04-05 06:49:26 | [diff] [blame] | 10 | #include "base/base_export.h" |
| pastarmovj | 89f7ee1 | 2016-09-20 14:58:13 | [diff] [blame] | 11 | #include "base/logging.h" |
| proberge | fe47600 | 2017-06-23 14:29:01 | [diff] [blame] | 12 | #include "build/build_config.h" |
| pastarmovj | 89f7ee1 | 2016-09-20 14:58:13 | [diff] [blame] | 13 | |
| 14 | namespace logging { |
| 15 | |
| 16 | // Keep in mind that the syslog is always active regardless of the logging level |
| 17 | // and applied flags. Use only for important information that a system |
| 18 | // administrator might need to maintain the browser installation. |
| 19 | #define SYSLOG_STREAM(severity) \ |
| Peter Kasting | 134ef9af | 2024-12-28 02:30:09 | [diff] [blame] | 20 | COMPACT_GOOGLE_LOG_EX_##severity(EventLogMessage).stream() |
| 21 | #define SYSLOG(severity) SYSLOG_STREAM(severity) |
| pastarmovj | 89f7ee1 | 2016-09-20 14:58:13 | [diff] [blame] | 22 | |
| Xiaohan Wang | 38e4ebb | 2022-01-19 06:57:43 | [diff] [blame] | 23 | #if BUILDFLAG(IS_WIN) |
| proberge | fe47600 | 2017-06-23 14:29:01 | [diff] [blame] | 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); |
| Roger Tawa | f761bb6 | 2018-10-09 20:19:27 | [diff] [blame] | 30 | |
| 31 | // The event source may get set more than once in tests. This function allows |
| 32 | // a test to reset the source when needed. |
| 33 | void BASE_EXPORT ResetEventSourceForTesting(); |
| Xiaohan Wang | 38e4ebb | 2022-01-19 06:57:43 | [diff] [blame] | 34 | #endif // BUILDFLAG(IS_WIN) |
| pastarmovj | a3eac43 | 2016-12-07 17:38:52 | [diff] [blame] | 35 | |
| pastarmovj | 89f7ee1 | 2016-09-20 14:58:13 | [diff] [blame] | 36 | // Creates a formatted message on the system event log. That would be the |
| 37 | // Application Event log on Windows and the messages log file on POSIX systems. |
| 38 | class BASE_EXPORT EventLogMessage { |
| 39 | public: |
| 40 | EventLogMessage(const char* file, int line, LogSeverity severity); |
| David Bienvenu | 5f4d4f03 | 2020-09-27 16:55:03 | [diff] [blame] | 41 | EventLogMessage(const EventLogMessage&) = delete; |
| 42 | EventLogMessage& operator=(const EventLogMessage&) = delete; |
| pastarmovj | 89f7ee1 | 2016-09-20 14:58:13 | [diff] [blame] | 43 | ~EventLogMessage(); |
| 44 | |
| 45 | std::ostream& stream() { return log_message_.stream(); } |
| 46 | |
| 47 | private: |
| 48 | LogMessage log_message_; |
| pastarmovj | 89f7ee1 | 2016-09-20 14:58:13 | [diff] [blame] | 49 | }; |
| 50 | |
| Maksim Ivanov | c1a6ac9 | 2021-11-02 17:50:49 | [diff] [blame] | 51 | void BASE_EXPORT SetSyslogLoggingForTesting(bool logging_enabled); |
| 52 | |
| pastarmovj | 89f7ee1 | 2016-09-20 14:58:13 | [diff] [blame] | 53 | } // namespace logging |
| 54 | |
| 55 | #endif // BASE_SYSLOG_LOGGING_H_ |