syslog_logging.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. #ifndef BASE_SYSLOG_LOGGING_H_
  5. #define BASE_SYSLOG_LOGGING_H_
  6. #include <iosfwd>
  7. #include "base/base_export.h"
  8. #include "base/logging.h"
  9. #include "build/build_config.h"
  10. namespace logging {
  11. // Keep in mind that the syslog is always active regardless of the logging level
  12. // and applied flags. Use only for important information that a system
  13. // administrator might need to maintain the browser installation.
  14. #define SYSLOG_STREAM(severity) \
  15. COMPACT_GOOGLE_LOG_EX_ ## severity(EventLogMessage).stream()
  16. #define SYSLOG(severity) \
  17. SYSLOG_STREAM(severity)
  18. #if BUILDFLAG(IS_WIN)
  19. // Sets the name, category and event id of the event source for logging to the
  20. // Windows Event Log. Call this function once before using the SYSLOG macro or
  21. // otherwise it will behave as a regular LOG macro.
  22. void BASE_EXPORT SetEventSource(const std::string& name,
  23. uint16_t category,
  24. uint32_t event_id);
  25. // The event source may get set more than once in tests. This function allows
  26. // a test to reset the source when needed.
  27. void BASE_EXPORT ResetEventSourceForTesting();
  28. #endif // BUILDFLAG(IS_WIN)
  29. // Creates a formatted message on the system event log. That would be the
  30. // Application Event log on Windows and the messages log file on POSIX systems.
  31. class BASE_EXPORT EventLogMessage {
  32. public:
  33. EventLogMessage(const char* file, int line, LogSeverity severity);
  34. EventLogMessage(const EventLogMessage&) = delete;
  35. EventLogMessage& operator=(const EventLogMessage&) = delete;
  36. ~EventLogMessage();
  37. std::ostream& stream() { return log_message_.stream(); }
  38. private:
  39. LogMessage log_message_;
  40. };
  41. void BASE_EXPORT SetSyslogLoggingForTesting(bool logging_enabled);
  42. } // namespace logging
  43. #endif // BASE_SYSLOG_LOGGING_H_