Chapter: Debugging and using jLog
« Configuring the error management | ^ Development helper tools | Creating unit tests » |
− Table of content
jLog ¶
jLog is a class which offers an api to trace, log messages or dump variables to a log output. The log output can be a classic file, syslog, firebug or other ways. Since Jelix 1.3, jLog supports plugins to add targets (called "loggers"), and is used to log error messages too.
jLog declares two static methods:
jLog::log($message, $logType)
to write a messagejLog::dump($variable, $message, $logType)
to write a variable content (concretely it callsvar_export
)
The default logger is the file logger. Messages are stored into var/log/messages.log
, or var/log/errors.log
for errors. $logType
(optional) indicate the type of the message. Each type is associated to one or more specific "loggers".
Configuring jLog ¶
To specify loggers, you must fill the [logger]
section. By default:
[logger]
_all =
default=file
error= file
warning=file
notice=file
deprecated=
strict=
debug=
Options names are types of messages. You can choose any name for type of message, although some are reserved:
default
: logger by defaulterror
,warning
,notice
,deprecated
,strict
: used by the error manager, for error messages.sql
, for jDb (in dev edition), to log sql queriessoap
, for jSoapClient, to log soap messages
And values are list of loggers (names of corresponding plugins). You can indicate :
file
to store in files. File names are indicated in a[filelogger]
section.syslog
to send messages to syslogfirebug
, to displays messages into the extension Firebug of Firefox.mail
, to send messages in a mail boxmemory
, to store messages in memory (temporary). It is needed for the debugbar or other components.- and any other plugin names you created or installed for jLog.
File logger ¶
When you use the file logger, you must indicate in which file you want to store messages. Files are indicated into the [filelogger]
section. Options are type of messages, and values are filenames (Into var/log/
).
Example (default values):
[fileLogger]
default=messages.log
error=errors.log
warning=errors.log
notice=errors.log
deprecated=errors.log
strict=errors.log
debug=debug.log
To ease collaboration development on a same server, it is also possible to distinguish each developer logs. The only requirement is a unique ip per developer. Just use "%ip%" pattern in the log output filename.
[fileLogger]
default = "messages_%ip%.log"
news = "%ip%_modulenews.log"
If a developer works on 192.168.1.2 host, his logs will be var/log/192.168.1.2_modulenews.log
and var/log/messages_192.168.1.2.log
.
Date and time can also be used in log filenames. Just include some of : %Y% (year), %m% (month), %d% (day), %H% (hour) pattern in log filenames.
mail logger ¶
To configure the mail logger, you should indicate the email and some headers, in the configuration:
[mailLogger]
email = root@localhost
emailHeaders = "Content-Type: text/plain; charset=UTF-8\nFrom: webmaster@yoursite.com\nX-Mailer: Jelix\nX-Priority: 1 (Highest)\n"
Avoid to use the mail logger, unless you know that your application is stable and errors are rare. Else you could receive tons of mails.
The debug bar ¶
Until Jelix 1.2, Jelix has displaying error messages (and only error messages) directly in the web page, in a simple box. Since Jelix 1.3, Jelix provides a true tools box, the debugbar, which displays every error messages and their details, and also many other informations: session data, sql queries etc. Each of these informations are provided by plugins. You can create your own plugins to enhance the debugbar.
The debugbar is a plugin itself for jResponseHtml. So to activate it:
- You must declare the "debugbar" plugin in the list of plugins of jResponseHtml
- You must activate the "memory" logger for each type of messages needed by the debugbar and its plugins.
- you need to indicate the list of plugins you want to use for the debugbar (by default : "sqllog, sessiondata, defaultlog").
Here is a typical example:
[jResponseHtml]
plugins = debugbar
[logger]
default=file,memory
error=file,memory
warning=file,memory
notice=file,memory
sql = memory
debug=memory
[debugbar]
plugins = sqllog,sessiondata,defaultlog