Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 18 additions & 10 deletions dist-persist/wbstack/src/Logging/CustomLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,39 @@ class CustomLogger extends AbstractLogger {
private $channel;
private $config;

public function __construct($channel, $config ) {
/**
* @param string $channel Logging channel
* @param array $config = [
* 'ignoreLevels' => (string[]) Ignore messages with these levels
* 'ignoreAllInGroup' => (string[]) Ignore messages in these channels
* 'logAllInGroup' => (string[]) Log all messages in these channels regardless
* of what is set in either 'ignoreLevels' or 'ignoreAllInGroup'
* 'logAllInGroupExceptDebug' => (string[]) Log all non-debug level messages
* in these channels regardless of what is set in either 'ignoreLevels'
* or 'ignoreAllInGroup'
* ]
*/
public function __construct( $channel, $config ) {
$this->channel = $channel;
$this->config = $config;
}

public function log( $level, $message, array $context = [] ) {
if(in_array($this->channel, $this->config['logAllInGroup'])) {
if( in_array( $this->channel, $this->config[ 'logAllInGroup'] ) ) {
$this->doLog( $level, $message, $context );
return;
}
if(in_array($this->channel, $this->config['logAllInGroupExceptDebug']) && $level !== 'debug') {
if( in_array( $this->channel, $this->config[ 'logAllInGroupExceptDebug' ] ) && $level !== 'debug' ) {
$this->doLog( $level, $message, $context );
return;
}

if(in_array($this->channel, $this->config['ignoreAllInGroup'])) {
if( in_array( $this->channel, $this->config[ 'ignoreAllInGroup' ] ) ) {
return;
}
if(in_array($level, $this->config['ignoreLevels'])) {
if( in_array( $level, $this->config[ 'ignoreLevels' ] ) ) {
return;
}

$this->doLog($level, $message, $context);
$this->doLog( $level, $message, $context );
}

private function doLog( $level, $message, $context ) {
Expand Down Expand Up @@ -62,8 +72,6 @@ private function doLog( $level, $message, $context ) {
if ( json_last_error() !== JSON_ERROR_NONE ) {
$output = "[$level] " . LegacyLogger::format( $this->channel, $message, $context );
}

fwrite( STDERR, $output . PHP_EOL );
}

}
25 changes: 13 additions & 12 deletions dist-persist/wbstack/src/Logging/CustomSpi.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,35 @@

class CustomSpi implements Spi {

// Array of channels to log
protected $config;

/**
* @param array $config Logger configuration
* @see CustomLogger::__construct()
*/
public function __construct( array $config ) {
// if(!array_key_exists('channels', $config)) {
// throw new \InvalidArgumentException('channels arg needed');
// }
if(!array_key_exists('ignoreLevels', $config)) {
if ( !array_key_exists( 'ignoreLevels', $config ) ) {
throw new \InvalidArgumentException('ignoreLevels arg needed');
}
if(!array_key_exists('ignoreAllInGroup', $config)) {
throw new \InvalidArgumentException('ignoreAllInGroup arg needed');
if ( !array_key_exists( 'ignoreAllInGroup', $config ) ) {
throw new \InvalidArgumentException( 'ignoreAllInGroup arg needed' );
}
if(!array_key_exists('logAllInGroup', $config)) {
throw new \InvalidArgumentException('logAllInGroup arg needed');
if ( !array_key_exists( 'logAllInGroup', $config ) ) {
throw new \InvalidArgumentException( 'logAllInGroup arg needed' );
}
if(!array_key_exists('logAllInGroupExceptDebug', $config)) {
throw new \InvalidArgumentException('logAllInGroupExceptDebug arg needed');
if ( !array_key_exists( 'logAllInGroupExceptDebug', $config ) ) {
throw new \InvalidArgumentException( 'logAllInGroupExceptDebug arg needed' );
}
$this->config = $config;
}

/**
* Get a logger instance.
*
* @param string $channel Logging channel
* @return \Psr\Log\AbstractLogger Logger instance
*/
public function getLogger( $channel ) {
return new CustomLogger( $channel, $this->config);
return new CustomLogger( $channel, $this->config );
}
}
28 changes: 18 additions & 10 deletions dist/wbstack/src/Logging/CustomLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,39 @@ class CustomLogger extends AbstractLogger {
private $channel;
private $config;

public function __construct($channel, $config ) {
/**
* @param string $channel Logging channel
* @param array $config = [
* 'ignoreLevels' => (string[]) Ignore messages with these levels
* 'ignoreAllInGroup' => (string[]) Ignore messages in these channels
* 'logAllInGroup' => (string[]) Log all messages in these channels regardless
* of what is set in either 'ignoreLevels' or 'ignoreAllInGroup'
* 'logAllInGroupExceptDebug' => (string[]) Log all non-debug level messages
* in these channels regardless of what is set in either 'ignoreLevels'
* or 'ignoreAllInGroup'
* ]
*/
public function __construct( $channel, $config ) {
$this->channel = $channel;
$this->config = $config;
}

public function log( $level, $message, array $context = [] ) {
if(in_array($this->channel, $this->config['logAllInGroup'])) {
if( in_array( $this->channel, $this->config[ 'logAllInGroup'] ) ) {
$this->doLog( $level, $message, $context );
return;
}
if(in_array($this->channel, $this->config['logAllInGroupExceptDebug']) && $level !== 'debug') {
if( in_array( $this->channel, $this->config[ 'logAllInGroupExceptDebug' ] ) && $level !== 'debug' ) {
$this->doLog( $level, $message, $context );
return;
}

if(in_array($this->channel, $this->config['ignoreAllInGroup'])) {
if( in_array( $this->channel, $this->config[ 'ignoreAllInGroup' ] ) ) {
return;
}
if(in_array($level, $this->config['ignoreLevels'])) {
if( in_array( $level, $this->config[ 'ignoreLevels' ] ) ) {
return;
}

$this->doLog($level, $message, $context);
$this->doLog( $level, $message, $context );
}

private function doLog( $level, $message, $context ) {
Expand Down Expand Up @@ -62,8 +72,6 @@ private function doLog( $level, $message, $context ) {
if ( json_last_error() !== JSON_ERROR_NONE ) {
$output = "[$level] " . LegacyLogger::format( $this->channel, $message, $context );
}

fwrite( STDERR, $output . PHP_EOL );
}

}
25 changes: 13 additions & 12 deletions dist/wbstack/src/Logging/CustomSpi.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,35 @@

class CustomSpi implements Spi {

// Array of channels to log
protected $config;

/**
* @param array $config Logger configuration
* @see CustomLogger::__construct()
*/
public function __construct( array $config ) {
// if(!array_key_exists('channels', $config)) {
// throw new \InvalidArgumentException('channels arg needed');
// }
if(!array_key_exists('ignoreLevels', $config)) {
if ( !array_key_exists( 'ignoreLevels', $config ) ) {
throw new \InvalidArgumentException('ignoreLevels arg needed');
}
if(!array_key_exists('ignoreAllInGroup', $config)) {
throw new \InvalidArgumentException('ignoreAllInGroup arg needed');
if ( !array_key_exists( 'ignoreAllInGroup', $config ) ) {
throw new \InvalidArgumentException( 'ignoreAllInGroup arg needed' );
}
if(!array_key_exists('logAllInGroup', $config)) {
throw new \InvalidArgumentException('logAllInGroup arg needed');
if ( !array_key_exists( 'logAllInGroup', $config ) ) {
throw new \InvalidArgumentException( 'logAllInGroup arg needed' );
}
if(!array_key_exists('logAllInGroupExceptDebug', $config)) {
throw new \InvalidArgumentException('logAllInGroupExceptDebug arg needed');
if ( !array_key_exists( 'logAllInGroupExceptDebug', $config ) ) {
throw new \InvalidArgumentException( 'logAllInGroupExceptDebug arg needed' );
}
$this->config = $config;
}

/**
* Get a logger instance.
*
* @param string $channel Logging channel
* @return \Psr\Log\AbstractLogger Logger instance
*/
public function getLogger( $channel ) {
return new CustomLogger( $channel, $this->config);
return new CustomLogger( $channel, $this->config );
}
}