spip_log

This function is used to record actions out to the log files (generally located in the tmp/log/ directory).

This function accepts 1 or 2 arguments. With one argument, it will write out to just the spip.log file. With two arguments it will write out to both a separate log file and also to the spip.log.

<?php
spip_log($tableau);
spip_log($tableau, 'second_file');
spip_log("adding field $champ into the $table table","my_plugin");
?>

When a table is passed to the log function, SPIP will write out the output from print_r() into the log file. For each file requested, in this case spip (by default) and second_file, SPIP will create or add the contents of the first argument, but not just anywhere. If the script is run from the private interface, it will write out to "prive_spip.log" or to "prive_second_file.log", otherwise it will write to "spip.log" or "second_file.log".

The configuration file ecrire/inc_version.php defines the maximum size of the log files. When a given log file exceeds this pre-determined file size, it is renamed prive_spip.log.n (n will automatically increment). The number of such files that may exist is also configurable. It is also possible to deactivate the logs by setting one of these specified values to zero within the mes_options.php file.

$GLOBALS['nombre_de_logs'] = 4; // maximum 4 log files
$GLOBALS['taille_des_logs'] = 100; // maximum 100 KB each

There is also a _MAX_LOG constant (set to 100 by default) which specifies the number of entries that each call from a given page may write to a log file. With this default setting, after 100 calls are made to spip_log() from any particular script, the log function will refuse to write any further content for that script.

Author Mark Baber Published : Updated : 12/03/23

Translations : English, français, Nederlands