mukesh agrawal | 7202e08 | 2012-02-09 15:30:14 -0800 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
Ken Mixter | f15efc6 | 2011-03-02 18:01:37 -0800 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Bertrand SIMONNET | b54b6dc | 2014-07-02 12:13:56 -0700 | [diff] [blame] | 5 | #ifndef LIBCHROMEOS_CHROMEOS_SYSLOG_LOGGING_H_ |
| 6 | #define LIBCHROMEOS_CHROMEOS_SYSLOG_LOGGING_H_ |
Ken Mixter | f15efc6 | 2011-03-02 18:01:37 -0800 | [diff] [blame] | 7 | |
| 8 | #include <string> |
| 9 | |
Alex Vakulenko | 847b871 | 2014-08-29 10:43:06 -0700 | [diff] [blame] | 10 | #include <chromeos/chromeos_export.h> |
| 11 | |
Ken Mixter | f15efc6 | 2011-03-02 18:01:37 -0800 | [diff] [blame] | 12 | namespace chromeos { |
| 13 | |
| 14 | enum InitFlags { |
| 15 | kLogToSyslog = 1, |
mukesh agrawal | 7202e08 | 2012-02-09 15:30:14 -0800 | [diff] [blame] | 16 | kLogToStderr = 2, |
| 17 | kLogHeader = 4, |
Ken Mixter | f15efc6 | 2011-03-02 18:01:37 -0800 | [diff] [blame] | 18 | }; |
| 19 | |
Christopher Wiley | a6b3fcd | 2012-08-10 10:44:03 -0700 | [diff] [blame] | 20 | // Initialize logging subsystem. |init_flags| is a bitfield, with bits defined |
| 21 | // in InitFlags above. |
Alex Vakulenko | 847b871 | 2014-08-29 10:43:06 -0700 | [diff] [blame] | 22 | CHROMEOS_EXPORT void InitLog(int init_flags); |
Christopher Wiley | a6b3fcd | 2012-08-10 10:44:03 -0700 | [diff] [blame] | 23 | // Gets the current logging flags. |
Alex Vakulenko | 847b871 | 2014-08-29 10:43:06 -0700 | [diff] [blame] | 24 | CHROMEOS_EXPORT int GetLogFlags(); |
Christopher Wiley | a6b3fcd | 2012-08-10 10:44:03 -0700 | [diff] [blame] | 25 | // Sets the current logging flags. |
Alex Vakulenko | 847b871 | 2014-08-29 10:43:06 -0700 | [diff] [blame] | 26 | CHROMEOS_EXPORT void SetLogFlags(int log_flags); |
Ken Mixter | f15efc6 | 2011-03-02 18:01:37 -0800 | [diff] [blame] | 27 | // Convenience function for configuring syslog via openlog. Users |
| 28 | // could call openlog directly except for naming collisions between |
| 29 | // base/logging.h and syslog.h. Similarly users cannot pass the |
| 30 | // normal parameters so we pick a representative set. |log_pid| |
| 31 | // causes pid to be logged with |ident|. |
Alex Vakulenko | 847b871 | 2014-08-29 10:43:06 -0700 | [diff] [blame] | 32 | CHROMEOS_EXPORT void OpenLog(const char* ident, bool log_pid); |
Ken Mixter | f15efc6 | 2011-03-02 18:01:37 -0800 | [diff] [blame] | 33 | // Start accumulating the logs to a string. This is inefficient, so |
| 34 | // do not set to true if large numbers of log messages are coming. |
| 35 | // Accumulated logs are only ever cleared when the clear function ings |
| 36 | // called. |
Alex Vakulenko | 847b871 | 2014-08-29 10:43:06 -0700 | [diff] [blame] | 37 | CHROMEOS_EXPORT void LogToString(bool enabled); |
Ken Mixter | f15efc6 | 2011-03-02 18:01:37 -0800 | [diff] [blame] | 38 | // Get the accumulated logs as a string. |
Alex Vakulenko | 847b871 | 2014-08-29 10:43:06 -0700 | [diff] [blame] | 39 | CHROMEOS_EXPORT std::string GetLog(); |
Ken Mixter | f15efc6 | 2011-03-02 18:01:37 -0800 | [diff] [blame] | 40 | // Clear the accumulated logs. |
Alex Vakulenko | 847b871 | 2014-08-29 10:43:06 -0700 | [diff] [blame] | 41 | CHROMEOS_EXPORT void ClearLog(); |
Ken Mixter | f15efc6 | 2011-03-02 18:01:37 -0800 | [diff] [blame] | 42 | // Returns true if the accumulated log contains the given string. Useful |
| 43 | // for testing. |
Alex Vakulenko | 847b871 | 2014-08-29 10:43:06 -0700 | [diff] [blame] | 44 | CHROMEOS_EXPORT bool FindLog(const char* string); |
Ken Mixter | f15efc6 | 2011-03-02 18:01:37 -0800 | [diff] [blame] | 45 | |
| 46 | } // namespace chromeos |
| 47 | |
Bertrand SIMONNET | b54b6dc | 2014-07-02 12:13:56 -0700 | [diff] [blame] | 48 | #endif // LIBCHROMEOS_CHROMEOS_SYSLOG_LOGGING_H_ |