| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef MOJO_PUBLIC_C_ENVIRONMENT_LOGGER_H_ | 5 #ifndef MOJO_PUBLIC_C_ENVIRONMENT_LOGGER_H_ |
| 6 #define MOJO_PUBLIC_C_ENVIRONMENT_LOGGER_H_ | 6 #define MOJO_PUBLIC_C_ENVIRONMENT_LOGGER_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 // |MojoLogLevel|: Used to specify the type of log message. Values are ordered | 10 // |MojoLogLevel|: Used to specify the type of log message. Values are ordered |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 #define MOJO_LOG_LEVEL_INFO ((MojoLogLevel)0) | 23 #define MOJO_LOG_LEVEL_INFO ((MojoLogLevel)0) |
| 24 #define MOJO_LOG_LEVEL_WARNING ((MojoLogLevel)1) | 24 #define MOJO_LOG_LEVEL_WARNING ((MojoLogLevel)1) |
| 25 #define MOJO_LOG_LEVEL_ERROR ((MojoLogLevel)2) | 25 #define MOJO_LOG_LEVEL_ERROR ((MojoLogLevel)2) |
| 26 #define MOJO_LOG_LEVEL_FATAL ((MojoLogLevel)3) | 26 #define MOJO_LOG_LEVEL_FATAL ((MojoLogLevel)3) |
| 27 #endif | 27 #endif |
| 28 | 28 |
| 29 // Structure with basic logging functions (on top of which more friendly logging | 29 // Structure with basic logging functions (on top of which more friendly logging |
| 30 // macros may be built). The functions are thread-safe, except for | 30 // macros may be built). The functions are thread-safe, except for |
| 31 // |SetMinimumLogLevel()| (see below). | 31 // |SetMinimumLogLevel()| (see below). |
| 32 struct MojoLogger { | 32 struct MojoLogger { |
| 33 // Logs |message| (which must not be null) at level |log_level| if |log_level| | 33 // Logs |message| at level |log_level| if |log_level| is at least the current |
| 34 // is at least the current minimum log level. If |log_level| is | 34 // minimum log level. If |log_level| is |MOJO_LOG_LEVEL_FATAL| (or greater), |
| 35 // |MOJO_LOG_LEVEL_FATAL| (or greater), aborts the application/process. | 35 // aborts the application/process. |
| 36 // |source_file| and |source_line| indicate the source file and (1-based) line | 36 void (*LogMessage)(MojoLogLevel log_level, const char* message); |
| 37 // number, respectively; they are optional: |source_file| may be null and | |
| 38 // |source_line| may be zero (if |source_file| is null, then |source_line| may | |
| 39 // be ignored). | |
| 40 void (*LogMessage)(MojoLogLevel log_level, | |
| 41 const char* source_file, | |
| 42 uint32_t source_line, | |
| 43 const char* message); | |
| 44 | 37 |
| 45 // Gets the minimum log level (see above), which will always be at most | 38 // Gets the minimum log level (see above), which will always be at most |
| 46 // |MOJO_LOG_LEVEL_FATAL|. (Though |LogMessage()| will automatically avoid | 39 // |MOJO_LOG_LEVEL_FATAL|. (Though |LogMessage()| will automatically avoid |
| 47 // logging messages below the minimum log level, this may be used to avoid | 40 // logging messages below the minimum log level, this may be used to avoid |
| 48 // extra work.) | 41 // extra work.) |
| 49 MojoLogLevel (*GetMinimumLogLevel)(void); | 42 MojoLogLevel (*GetMinimumLogLevel)(void); |
| 50 | 43 |
| 51 // Sets the minimum log level (see above) to the lesser of |minimum_log_level| | 44 // Sets the minimum log level (see above) to the lesser of |minimum_log_level| |
| 52 // and |MOJO_LOG_LEVEL_FATAL|. | 45 // and |MOJO_LOG_LEVEL_FATAL|. |
| 53 // | 46 // |
| 54 // Warning: This function may not be thread-safe, and should not be called | 47 // Warning: This function may not be thread-safe, and should not be called |
| 55 // concurrently with other |MojoLogger| functions. (In some environments -- | 48 // concurrently with other |MojoLogger| functions. (In some environments -- |
| 56 // such as Chromium -- that share a logger across applications, this may mean | 49 // such as Chromium -- that share a logger across applications, this may mean |
| 57 // that it is almost never safe to call this.) | 50 // that it is almost never safe to call this.) |
| 58 void (*SetMinimumLogLevel)(MojoLogLevel minimum_log_level); | 51 void (*SetMinimumLogLevel)(MojoLogLevel minimum_log_level); |
| 59 }; | 52 }; |
| 60 | 53 |
| 61 #endif // MOJO_PUBLIC_C_ENVIRONMENT_LOGGER_H_ | 54 #endif // MOJO_PUBLIC_C_ENVIRONMENT_LOGGER_H_ |
| OLD | NEW |