Home | History | Annotate | Download | only in brillo
      1 // Copyright (c) 2012 The Chromium OS 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 
      5 #ifndef LIBBRILLO_BRILLO_SYSLOG_LOGGING_H_
      6 #define LIBBRILLO_BRILLO_SYSLOG_LOGGING_H_
      7 
      8 #include <string>
      9 
     10 #include <brillo/brillo_export.h>
     11 
     12 namespace brillo {
     13 
     14 enum InitFlags {
     15   // Always log to syslog.
     16   kLogToSyslog = 1,
     17   // Always log to stderr.
     18   kLogToStderr = 2,
     19   // Include message header in log lines.
     20   kLogHeader = 4,
     21   // Log to stderr if stdin is a tty (e.g. command line).
     22   kLogToStderrIfTty = 8,
     23 };
     24 
     25 // Initialize logging subsystem.  |init_flags| is a bitfield, with bits defined
     26 // in InitFlags above.
     27 BRILLO_EXPORT void InitLog(int init_flags);
     28 // Gets the current logging flags.
     29 BRILLO_EXPORT int GetLogFlags();
     30 // Sets the current logging flags.
     31 BRILLO_EXPORT void SetLogFlags(int log_flags);
     32 // Convenience function for configuring syslog via openlog.  Users
     33 // could call openlog directly except for naming collisions between
     34 // base/logging.h and syslog.h.  Similarly users cannot pass the
     35 // normal parameters so we pick a representative set.  |log_pid|
     36 // causes pid to be logged with |ident|.
     37 BRILLO_EXPORT void OpenLog(const char* ident, bool log_pid);
     38 // Start accumulating the logs to a string.  This is inefficient, so
     39 // do not set to true if large numbers of log messages are coming.
     40 // Accumulated logs are only ever cleared when the clear function ings
     41 // called.
     42 BRILLO_EXPORT void LogToString(bool enabled);
     43 // Get the accumulated logs as a string.
     44 BRILLO_EXPORT std::string GetLog();
     45 // Clear the accumulated logs.
     46 BRILLO_EXPORT void ClearLog();
     47 // Returns true if the accumulated log contains the given string.  Useful
     48 // for testing.
     49 BRILLO_EXPORT bool FindLog(const char* string);
     50 
     51 }  // namespace brillo
     52 
     53 #endif  // LIBBRILLO_BRILLO_SYSLOG_LOGGING_H_
     54