Documentation

AddMessage2Log

AddMessage2Log(
 string text,
 string module_id = "",
 traceDepth = 6,
 bool ShowArgs = false
);

This function adds a new record into the log file. It's recommended to specify a unique path to file (of file name) within each project.

Prior to calling this function, the LOG_FILENAME constant, containing absolute path to the log file, must be defined. When this constant is not defined, function does not perform any actions. If required, LOG_FILENAME constant is defined at the start of the current page or in one of the following files:

  • /bitrix/php_interface/dbconn.php
  • /bitrix/php_interface/site ID/init.php

If an error occurs, this function is called by the following functions:

Log file accumulates all message records added to it. To clean the log file, delete it from the drive.

Note. All database queries and their time specs can be recorded into a separate debugging file. To enable this option, initialize [link=6658210#dbdebugtofile]$DBDebugToFile variable[/link], with "true" value in the file /bitrix/php_interface/dbconn.php.

You can dump all database queries for debugging purposes. To do so, initialize the $DBDebugToFile variable with true in the file /bitrix/php_interface/dbconn.php.

Analogue function in the the new core: Bitrix\Main\Diag\Debug::dumpToFile and Bitrix\Main\Diag\Debug::writeToFile.

Function parameters

ParameterDescription Available from version
text Message text.
module_id The ID of the module, that saves a message.
Optional parameter, "" by default.
traceDepth Optional parameter, "6" by default.
ShowArgs Optional parameter, false by default .

See Also

[link=6658210#dbdebug] Special variables for debugging[/link]

Examples of use

<?
// file /bitrix/php_interface/dbconn.php

// define LOG_FILENAME constant, containing path to the log file
define("LOG_FILENAME", $_SERVER["DOCUMENT_ROOT"]."/log.txt");
?>
<?
// Save message into the log
AddMessage2Log("Random text message", "my_module_id");
?>
<?
// initiate premeditated incorrect SQL query
$DB->Query("SELECT");
// the script is halted and an error message is added to log
?>
define("LOG_FILENAME", $_SERVER["DOCUMENT_ROOT"] . "/_logs/bx/" . date("Y_m_d") . "_PROJECT_UNIQUE_POSTFIX.log");


© «Bitrix24», 2001-2022
Up