Posts Tagged ‘normal’

Using DooPHP Logging Tools

DooPHP comes with its own profiler and logging tool by default. The class that handle this in the framework is DooLog (dooframework/app/logging/DooLog.php)

There are a few methods in this file where you can use for profiling and logging queries or important message in your application. You can log a message by calling:

Doo::logger()->log('Something fishy here!', DooLog::Alert);

Or you can use the Alias methods instead of passing the log level:

Doo::logger()->alert('Something fishy here!');
Doo::logger()->emerg('message...');
Doo::logger()->crit('message...');
Doo::logger()->err('message...');
Doo::logger()->warn('message...');
Doo::logger()->notice('message...');
Doo::logger()->info('message...');
Doo::logger()->trace('message...');

All of the log messages can be organized by category, simply pass in another parameter at the end of the methods:

Doo::logger()->log('Something fishy here!', DooLog::ALERT, 'editpost');
Doo::logger()->emerg('message...', 'editpost');
Doo::logger()->alert('message...', 'editpost');

To view the logged messages, you just have to call showLogs(). By default DooLog will return a neatly formatted XML log which can be filtered by level or category. You can get a plain text log if you need so:

//display all logs
echo Doo::logger()->showLogs();

//display plain text log
echo Doo::logger()->showLogs(false);

//display only logs in category editpost
echo Doo::logger()->showLogs(true, null, 'editpost');

//display only logs in level Alert and category editpost
echo Doo::logger()->showLogs(true, DooLog::ALERT, 'editpost');

When you have to write the log messages into file, all you have to do is call writeLogs(). Similar to showLogs(), it writes the XML string to file by default.


//Creates a log file
More »