Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- define( "DEBUG", true );
- class Logger
- {
- private $_traceOutput;
- private $_debugOutput;
- private $_isDebugActive;
- static private $_instance;
- static public function init( $traceOutput = STDOUT , $debugOutput = STDERR )
- {
- self::$_instance = new Logger( $traceOutput, $debugOutput );
- }
- static public function getInstance( )
- {
- return self::$_instance;
- }
- static public function trace( $msg )
- {
- self::$_instance->traceMessage( $msg );
- }
- static public function debug( $msg )
- {
- self::$_instance->debugMessage( $msg );
- }
- public function __construct( $traceOutput, $debugOutput )
- {
- $this->_traceOutput = $traceOutput;
- $this->_debugOutput = $debugOutput;
- // _isDebugActive indica se siamo in debug mode o meno
- $this->_isDebugActive = DEBUG;
- }
- public function __destruct()
- {
- fclose( $this->_debugOutput );
- fclose( $this->_traceOutput );
- }
- public function getDebugModeIsOn()
- {
- return $this->_isDebugActive;
- }
- private function writeOnDebug( $handle, $message )
- {
- if( $this->getDebugModeIsOn() )
- {
- fwrite( $handle, $message );
- }
- }
- public function traceMessage( $message )
- {
- $this->writeOnDebug( $this->_traceOutput, $message );
- }
- public function debugMessage( $message )
- {
- $this->writeOnDebug( $this->_debugOutput, $message );
- }
- }
- Logger::init();
- Logger::debug( "lol\n" );
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement