ASL
|
Log is a utility to log messages to either the console, a file or both.
Messages have a category (usuarlly a module or area identifier) and a level (to distinguish errors, warnings, information and debug messages), and are written together with the current date and time. By default messages are written to a file named "log.log" and to the console (with errors and warnings colored). These, as well as the maximum log level of messages logged, can be configured.
Default settings can be changed like this:
The easiest way to write messages is with the provided macro ASL_LOG_ similar to a printf
call. It uses the current source file as category.
Writes something like:
There are recommended shorter macros for each log level: ASL_LOG_X (with X one of E, W, I, D, V):
On Android this class uses the system logger.
Log files do not grow indefinitely. When reaching about 1 MB, they will be moved to a file with "-1" appended to its name (like "log-1.log"), and a new empty file will be started. Any logs older than that will be lost.
#include <Log.h>
Public Types | |
enum | Level |
Message levels (ERR, WARNING, INFO, DEBUG, VERBOSE). | |
Static Public Member Functions | |
static void | setFile (const String &file) |
Sets the name of the file to write messages to. | |
static void | enable (bool on) |
Enables or disables logging. | |
static void | useConsole (bool on) |
Enables or disables writing messages to the console. | |
static void | useFile (bool on) |
Enables or disables writing messages to a file. | |
static void | setMaxLevel (int level) |
Sets the maximum level of messages to be logged; By default this is 3, so messages up to level DEBUG are logged. | |
static int | maxLevel () |
Gets the current maximum log level. | |
Static Public Member Functions inherited from Singleton< Log > | |
static Log * | instance () |
Returns a pointer to an instance of class T, creating it on the first call. | |
Friends | |
void | log (const String &cat, Log::Level level, const String &message) |
void | log (const String &cat, Log::Level level, const char *fmt,...) ASL_PRINTF_W2(3) |
Writes a printf-like formatted log message with the given category and log level. | |
|
friend |
Writes a log message with the given category and log level.