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