syslog_logging.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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();
  34. std::ostream& stream() { return log_message_.stream(); }
  35. private:
  36. LogMessage log_message_;
  37. DISALLOW_COPY_AND_ASSIGN(EventLogMessage);
  38. };
  39. } // namespace logging
  40. #endif // BASE_SYSLOG_LOGGING_H_