Created
June 26, 2013 04:37
-
-
Save umidjons/5864820 to your computer and use it in GitHub Desktop.
BX: AddMessage2Log() implementation from Bitrix Framework
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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