Skip to content

Instantly share code, notes, and snippets.

@umidjons
Created June 26, 2013 04:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save umidjons/5864820 to your computer and use it in GitHub Desktop.
Save umidjons/5864820 to your computer and use it in GitHub Desktop.
BX: AddMessage2Log() implementation from Bitrix Framework
<?php
function AddMessage2Log( $sText, $sModule = "" )
{
if ( defined( "LOG_FILENAME" ) && strlen( LOG_FILENAME ) > 0 ) {
if ( strlen( $sText ) > 0 ) {
ignore_user_abort( true );
if ( $fp = @fopen( LOG_FILENAME, "ab+" ) ) {
if ( flock( $fp, LOCK_EX ) ) {
@fwrite( $fp, date( "Y-m-d H:i:s" ) . " - " . $sModule . " - " . $sText . "\n" );
if ( function_exists( "debug_backtrace" ) ) {
$arBacktrace = debug_backtrace();
$strFunctionStack = "";
$iterationsCount = min( count( $arBacktrace ), 4 );
for ( $i = 1; $i < $iterationsCount; $i++ ) {
if ( strlen( $strFunctionStack ) > 0 ) {
$strFunctionStack .= " < ";
}
if ( strlen( $arBacktrace[ $i ][ "class" ] ) > 0 ) {
$strFunctionStack .= $arBacktrace[ $i ][ "class" ] . "::";
}
$strFunctionStack .= $arBacktrace[ $i ][ "function" ];
}
if ( strlen( $strFunctionStack ) > 0 ) {
@fwrite( $fp, " " . $strFunctionStack . "\n" );
}
}
@fwrite( $fp, "----------\n" );
@fflush( $fp );
@flock( $fp, LOCK_UN );
@fclose( $fp );
}
}
ignore_user_abort( false );
}
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment