Skip to content

Commit

Permalink
These can be removed and rely on the instances instead now
Browse files Browse the repository at this point in the history
  • Loading branch information
lux committed Dec 10, 2023
1 parent b0a7f02 commit e6f937d
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 101 deletions.
30 changes: 1 addition & 29 deletions lib/Analog/Handler/Buffer.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,40 +21,12 @@
* to the buffer.
*/
class Buffer {
/**
* This builds a log string of all messages logged.
*/
public static $buffer = '';

/**
* This contains the handler to send to on close.
*/
private static $handler;

/**
* A copy of our destructor object that will call close() on our behalf,
* since static classes can't have their own __destruct() methods.
*/
private static $destructor;

/**
* Accepts another handler function to be used on close().
*/
public static function init ($handler) {
self::$handler = $handler;
self::$destructor = new \Analog\Handler\Buffer\Destructor ();

return function ($info) {
Buffer::$buffer .= vsprintf (\Analog\Analog::$format, $info);
};
}

/**
* Passes the buffered log to the final $handler.
*/
public static function close () {
$handler = self::$handler;
return $handler (self::$buffer, true);
return new Buffer ($handler);
}

/**
Expand Down
28 changes: 1 addition & 27 deletions lib/Analog/Handler/LevelBuffer.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,39 +26,13 @@
* to the buffer.
*/
class LevelBuffer {
/**
* This builds a log string of all messages logged.
*/
public static $buffer = '';

/**
* This contains the handler to send to on close.
*/
private static $handler;

/**
* Accepts another handler function to be used on close().
* $until_level defaults to CRITICAL.
*/
public static function init ($handler, $until_level = 2) {
self::$handler = $handler;

return function ($info) use ($until_level) {
LevelBuffer::$buffer .= vsprintf (\Analog\Analog::$format, $info);
if ($info['level'] <= $until_level) {
// flush and reset the buffer
LevelBuffer::flush ();
LevelBuffer::$buffer = '';
}
};
}

/**
* Passes the buffered log to the final $handler.
*/
public static function flush () {
$handler = self::$handler;
return $handler (self::$buffer, true);
return new LevelBuffer ($handler, $until_level);
}

/**
Expand Down
15 changes: 1 addition & 14 deletions lib/Analog/Handler/LevelName.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,8 @@ class LevelName {
\Analog\Analog::URGENT => 'URGENT'
);

/**
* This contains the handler to send to
*/
public static $handler;

public static function init ($handler) {
self::$handler = $handler;

return function ($info) {
if (isset(self::$log_levels[$info['level']])) {
$info['level'] = self::$log_levels[$info['level']];
}
$handler = LevelName::$handler;
$handler ($info);
};
return new LevelName ($handler);
}

/**
Expand Down
19 changes: 1 addition & 18 deletions lib/Analog/Handler/Multi.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,7 @@
*/
class Multi {
public static function init ($handlers) {
return function ($info) use ($handlers) {
$level = is_numeric ($info['level']) ? $info['level'] : 3;
while ($level <= 7) {
if ( isset ( $handlers[ $level ] ) ) {

if ( ! is_array( $handlers[ $level ] ) ) {
$handlers[ $level ] = array( $handlers[ $level ] );
}

foreach ( $handlers[ $level ] as $handler ) {
$handler( $info );
}

return;
}
$level++;
}
};
return new Multi ($handlers);
}

/**
Expand Down
15 changes: 2 additions & 13 deletions lib/Analog/Handler/Threshold.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,13 @@
* to the buffer.
*/
class Threshold {
/**
* This contains the handler to send to on close.
*/
public static $handler;

/**
* Accepts another handler function to be used on close().
* $until_level defaults to ERROR.
*/
public static function init ($handler, $until_level = 3) {
self::$handler = $handler;

return function ($info) use ($until_level) {
if ($info['level'] <= $until_level) {
$handler = Threshold::$handler;
$handler ($info);
}
};
return new Threshold ($handler, $until_level);
}

/**
Expand All @@ -54,7 +43,7 @@ public function __construct ($handler, $until_level = 3) {
}

public function log ($info) {
if ($inf['level'] <= $this->_until_level) {
if ($info['level'] <= $this->_until_level) {
call_user_func ($this->_handler, $info);
}
}
Expand Down

0 comments on commit e6f937d

Please sign in to comment.