blob: 134d3cc9203f5acc89f63f5283adee99ac9523a5 [file] [log] [blame]
mukesh agrawal7202e082012-02-09 15:30:14 -08001// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
Ken Mixterf15efc62011-03-02 18:01:37 -08002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Bertrand SIMONNETb54b6dc2014-07-02 12:13:56 -07005#ifndef LIBCHROMEOS_CHROMEOS_SYSLOG_LOGGING_H_
6#define LIBCHROMEOS_CHROMEOS_SYSLOG_LOGGING_H_
Ken Mixterf15efc62011-03-02 18:01:37 -08007
8#include <string>
9
Alex Vakulenko847b8712014-08-29 10:43:06 -070010#include <chromeos/chromeos_export.h>
11
Ken Mixterf15efc62011-03-02 18:01:37 -080012namespace chromeos {
13
14enum InitFlags {
15 kLogToSyslog = 1,
mukesh agrawal7202e082012-02-09 15:30:14 -080016 kLogToStderr = 2,
17 kLogHeader = 4,
Ken Mixterf15efc62011-03-02 18:01:37 -080018};
19
Christopher Wileya6b3fcd2012-08-10 10:44:03 -070020// Initialize logging subsystem. |init_flags| is a bitfield, with bits defined
21// in InitFlags above.
Alex Vakulenko847b8712014-08-29 10:43:06 -070022CHROMEOS_EXPORT void InitLog(int init_flags);
Christopher Wileya6b3fcd2012-08-10 10:44:03 -070023// Gets the current logging flags.
Alex Vakulenko847b8712014-08-29 10:43:06 -070024CHROMEOS_EXPORT int GetLogFlags();
Christopher Wileya6b3fcd2012-08-10 10:44:03 -070025// Sets the current logging flags.
Alex Vakulenko847b8712014-08-29 10:43:06 -070026CHROMEOS_EXPORT void SetLogFlags(int log_flags);
Ken Mixterf15efc62011-03-02 18:01:37 -080027// 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 Vakulenko847b8712014-08-29 10:43:06 -070032CHROMEOS_EXPORT void OpenLog(const char* ident, bool log_pid);
Ken Mixterf15efc62011-03-02 18:01:37 -080033// 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 Vakulenko847b8712014-08-29 10:43:06 -070037CHROMEOS_EXPORT void LogToString(bool enabled);
Ken Mixterf15efc62011-03-02 18:01:37 -080038// Get the accumulated logs as a string.
Alex Vakulenko847b8712014-08-29 10:43:06 -070039CHROMEOS_EXPORT std::string GetLog();
Ken Mixterf15efc62011-03-02 18:01:37 -080040// Clear the accumulated logs.
Alex Vakulenko847b8712014-08-29 10:43:06 -070041CHROMEOS_EXPORT void ClearLog();
Ken Mixterf15efc62011-03-02 18:01:37 -080042// Returns true if the accumulated log contains the given string. Useful
43// for testing.
Alex Vakulenko847b8712014-08-29 10:43:06 -070044CHROMEOS_EXPORT bool FindLog(const char* string);
Ken Mixterf15efc62011-03-02 18:01:37 -080045
46} // namespace chromeos
47
Bertrand SIMONNETb54b6dc2014-07-02 12:13:56 -070048#endif // LIBCHROMEOS_CHROMEOS_SYSLOG_LOGGING_H_