Thanks to visit codestin.com
Credit goes to chromium.googlesource.com

blob: 259686de56692889fd36ba38928b2bcc78dab3e3 [file] [log] [blame]
Avi Drissmane4622aa2022-09-08 20:36:061// Copyright 2016 The Chromium Authors
pastarmovj89f7ee12016-09-20 14:58:132// 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
probergefe476002017-06-23 14:29:018#include <iosfwd>
9
David Sanders6e709942022-04-05 06:49:2610#include "base/base_export.h"
pastarmovj89f7ee12016-09-20 14:58:1311#include "base/logging.h"
probergefe476002017-06-23 14:29:0112#include "build/build_config.h"
pastarmovj89f7ee12016-09-20 14:58:1313
14namespace 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 Kasting134ef9af2024-12-28 02:30:0920 COMPACT_GOOGLE_LOG_EX_##severity(EventLogMessage).stream()
21#define SYSLOG(severity) SYSLOG_STREAM(severity)
pastarmovj89f7ee12016-09-20 14:58:1322
Xiaohan Wang38e4ebb2022-01-19 06:57:4323#if BUILDFLAG(IS_WIN)
probergefe476002017-06-23 14:29:0124// 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.
27void BASE_EXPORT SetEventSource(const std::string& name,
28 uint16_t category,
29 uint32_t event_id);
Roger Tawaf761bb62018-10-09 20:19:2730
31// The event source may get set more than once in tests. This function allows
32// a test to reset the source when needed.
33void BASE_EXPORT ResetEventSourceForTesting();
Xiaohan Wang38e4ebb2022-01-19 06:57:4334#endif // BUILDFLAG(IS_WIN)
pastarmovja3eac432016-12-07 17:38:5235
pastarmovj89f7ee12016-09-20 14:58:1336// 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.
38class BASE_EXPORT EventLogMessage {
39 public:
40 EventLogMessage(const char* file, int line, LogSeverity severity);
David Bienvenu5f4d4f032020-09-27 16:55:0341 EventLogMessage(const EventLogMessage&) = delete;
42 EventLogMessage& operator=(const EventLogMessage&) = delete;
pastarmovj89f7ee12016-09-20 14:58:1343 ~EventLogMessage();
44
45 std::ostream& stream() { return log_message_.stream(); }
46
47 private:
48 LogMessage log_message_;
pastarmovj89f7ee12016-09-20 14:58:1349};
50
Maksim Ivanovc1a6ac92021-11-02 17:50:4951void BASE_EXPORT SetSyslogLoggingForTesting(bool logging_enabled);
52
pastarmovj89f7ee12016-09-20 14:58:1353} // namespace logging
54
55#endif // BASE_SYSLOG_LOGGING_H_