diff --git "a/include/class-cli\\Log.php" "b/include/class-cli\\Log.php" index 0d2e314..d2a8869 100644 --- "a/include/class-cli\\Log.php" +++ "b/include/class-cli\\Log.php" @@ -1,133 +1,138 @@ . # Command line interface namespace cli; /** * Show log messages (when in CLI) */ class Log { /** * Normal information messages flag * * @var bool */ public static $INFO = true; /** * Verbose information messages flag * * @var bool */ public static $DEBUG = false; /** * Verbose sensitive information messages flag * * @var bool */ public static $SENSITIVE = false; /** * Show a warning * * Use it for errors that can be solved without interaction * * @param $message string * @param $args array arguments */ public static function warn( $message, $args = [] ) { self::log( 'WARN', $message, $args ); } /** * Show a debug information * * Use it to show actions under the hood * * @param $message string * @param $args array arguments */ public static function info( $message, $args = [] ) { if( self::$INFO ) { self::log( 'INFO', $message, $args ); } } /** * Show a debug information * * Use it to show actions under the hood * * @param $message string * @param $args array arguments */ - public static function debug( $message, $args ) { + public static function debug( $message, $args = [] ) { if( self::$DEBUG ) { self::log( 'DEBUG', $message, $args ); } } /** * Show an error * * @param $message string * @param $args array arguments */ public static function error( $message, $args = [] ) { - self::log( 'ERROR', $message ); + self::log( 'ERROR', $message, $args ); } /** * Show a debug information message that contains sensitive informations * * @param $message_sensitive Message with sensitive informations * @param $message_unsensitive Message secure to be shown * @param $args array arguments */ public static function sensitive( $message_sensitive, $message_unsensitive, $args = [] ) { if( self::$DEBUG ) { if( self::$SENSITIVE ) { - self::log( '!DEBUG!', $message_sensitive ); + self::log( '!DEBUG!', $message_sensitive, $args ); } elseif( $message_unsensitive ) { - self::log( '!DEBUG!', "$message_unsensitive [SENSITIVE DATA HIDDEN]" ); + self::log( '!DEBUG!', "$message_unsensitive [SENSITIVE DATA HIDDEN]", $args ); } } } /** * Show a message * * @param $type string * @param $message string * @param $args array arguments */ public static function log( $type, $message, $args = [] ) { - if( ! @ $args[ 'newline' ] ) { + // default arguments + $args = array_replace( [ + 'newline' => true, + ], $args ); + + if( $args[ 'newline' ] ) { $message .= "\n"; } if( isset( $_SERVER['argv'] ) ) { $date = date( 'Y-m-d H:i:s' ); printf( "[%s][%s] %s", $date, $type, $message ); } else { error_log( "$type $message" ); } } }