Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Master #1

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* [kohana-minion](https://github.com/kohana-minion/core) is not strictly required, but this was written with minion/command line interfaces in mind.

## Compatibility
* Written for Kohana 3.2.
* Written for Kohana 3.3 and 3.2.

## Usage

Expand Down Expand Up @@ -56,4 +56,4 @@ That's why this is hosted on github :). Feel free to fork it, submit issues, or

## License

This is licensed under the [same license as Kohana](http://kohanaframework.org/license).
This is licensed under the [same license as Kohana](http://kohanaframework.org/license).
118 changes: 118 additions & 0 deletions classes/Kohana/Minion/Log.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
<?php

defined('SYSPATH') OR die('No direct script access.');

/**
* Extend the Log class to support write_on_add to individual log writers
*
* @abstract
* @extends Log
*/
abstract class Kohana_Minion_Log extends Log
{

/**
* @var array Log writers that should write out as soon as soon as messages are added
* @access protected
*/
protected $_on_add_writers = array();

/**
* @var mixed Log writers that should write out as soon as soon as messages are added
* @static override instance
* @access protected
*/
protected static $_instance = NULL;

/**
* Attaches a log writer, and optionally limits the levels of messages that
* will be written by the writer.
*
* $log->attach($writer);
*
* @param Log_Writer $writer instance
* @param mixed $levels array of messages levels to write OR max level to write
* @param integer $min_level min level to write IF $levels is not an array
* @param boolean $write_on_add Should we write to this log immediately?
* @return Minion_Log
*/
public function attach(Log_Writer $writer, $levels = array(), $min_level = 0, $write_on_add = FALSE)
{
parent::attach($writer, $levels, $min_level);

if ($write_on_add) {
$this->_on_add_writers["{$writer}"] = $this->_writers["{$writer}"];
unset($this->_writers["{$writer}"]);
}

return $this;
}

/**
* Detaches a log writer. The same writer object must be used.
*
* $log->detach($writer);
*
* @param Log_Writer $writer instance
* @return Minion_Log
*/
public function detach(Log_Writer $writer)
{
unset($this->_on_add_writers["{$writer}"]);
return parent::detach($writer);
}

/**
* Adds a message to the log. Replacement values must be passed in to be
* replaced using [strtr](http://php.net/strtr).
*
* $log->add(Log::ERROR, 'Could not locate user: :user', array(
* ':user' => $username,
* ));
*
* @param string $level level of message
* @param string $message message body
* @param array $values values to replace in the message
* @return Minion_Log
*/
public function add($level, $message, array $values = NULL, array $additional = NULL)
{
parent::add($level, $message, $values, $additional);

if (!empty($this->_on_add_writers)) {
// Get the last message
$msg = end($this->_messages);
reset($this->_messages);

foreach ($this->_on_add_writers as $writer) {
if (empty($writer['levels']) OR in_array($msg['level'], $writer['levels'])) {
$writer['object']->write(array($msg));
}
}
}

return $this;
}

/**
* Get the singleton instance of this class and enable writing at shutdown.
* This can be different from the default Kohana logger
*
* $log = Minion_Log::instance();
*
* @return Minion_Log
*/
public static function instance()
{
if (Minion_Log::$_instance === NULL) {
// Create a new instance
Minion_Log::$_instance = new Minion_Log;

// Write the logs at shutdown
register_shutdown_function(array(Minion_Log::$_instance, 'write'));
}

return Minion_Log::$_instance;
}

}
File renamed without changes.
119 changes: 0 additions & 119 deletions classes/kohana/minion/log.php

This file was deleted.

30 changes: 30 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "seyfer/kohana-minion-log",
"version": "3.3",
"description": "Kohana module to log while in CLI environment",
"type": "kohana-module",
"authors": [
{
"name": "seyfer",
"email": "[email protected]",
"homepage": "http://seyferseed.ru",
"role": "Developer"
}
],
"require": {
"php": ">=5.4",
"composer/installers": "1.*"
},
"autoload": {
"classmap": [
"classes/"
]
},
"extra": {
"installer-paths": {
"vendor/kohana/modules/{$name}/": [
"type:kohana-module"
]
}
}
}
Loading