syslog_logging.h 1.8 KB

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