Skip to content

Commit

Permalink
Merge pull request #20 from rantonmattei/monologger
Browse files Browse the repository at this point in the history
Renamed MonoLogger to Cascade + added an alias to the getLogger function
  • Loading branch information
rantonmattei committed Jun 18, 2015
2 parents 74dd158 + a9146e1 commit c136593
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 22 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ Usage

```php
<?php
use Cascade\MonoLogger;
use Cascade\Cascade;

// configure your loggers
MonoLogger::fileConfig('path/to/some/config.yaml');
Cascade::fileConfig('path/to/some/config.yaml');
```

Then just use your logger as shown below
```php
MonoLogger::getLogger('myApp')->info('Well, that works!');
MonoLogger::getLogger('myApp')->error('Maybe not...');
Cascade::getLogger('myApp')->info('Well, that works!');
Cascade::getLogger('myApp')->error('Maybe not...');
```

Configuring your loggers
Expand Down
8 changes: 4 additions & 4 deletions examples/multiple_loggers.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<?php
require_once(realpath(__DIR__.'/../vendor/autoload.php'));

use Cascade\MonoLogger;
use Cascade\Cascade;

$loggerConfigFile = realpath(__DIR__.'/logger_config.yml');

// you can use json too!
// $loggerConfigFile = realpath(__DIR__.'/logger_config.json');

MonoLogger::fileConfig($loggerConfigFile);
MonoLogger::getLogger('loggerA')->info('Well, that works!');
MonoLogger::getLogger('loggerB')->error('Maybe not...');
Cascade::fileConfig($loggerConfigFile);
Cascade::getLogger('loggerA')->info('Well, that works!');
Cascade::getLogger('loggerB')->error('Maybe not...');

// This should log into 2 different log files depending on the level: 'example_info.log' and 'example_error.log'
4 changes: 2 additions & 2 deletions examples/single_logger.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php
require_once(realpath(__DIR__.'/../vendor/autoload.php'));

use Cascade\MonoLogger;
use Cascade\Cascade;

$logger = MonoLogger::getLogger('some_logger');
$logger = Cascade::getLogger('some_logger');
$logger->pushHandler(new Monolog\Handler\StreamHandler('php://stdout'));
$logger->info('Hellooooo World!');

Expand Down
14 changes: 13 additions & 1 deletion src/MonoLogger.php → src/Cascade.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*
* @author Raphael Antonmattei <[email protected]>
*/
class MonoLogger
class Cascade
{
/**
* Config class that holds options for all registered loggers
Expand Down Expand Up @@ -65,6 +65,18 @@ public static function getLogger($name)
return Registry::hasLogger($name) ? Registry::getInstance($name) : self::createLogger($name);
}

/**
* Alias of getLogger
* @see getLogger
*
* @param string $name Name of the requested Logger instance
* @return Monolog\Logger Requested instance of Logger or new instance
*/
public static function logger($name)
{
return self::getLogger($name);
}

/**
* Return the config options
*
Expand Down
4 changes: 2 additions & 2 deletions src/Config/Loader/ClassLoader/LoggerLoader.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
namespace Cascade\Config\Loader\ClassLoader;

use Cascade\MonoLogger;
use Cascade\Cascade;
use Cascade\Config\Loader\ClassLoader;

/**
Expand Down Expand Up @@ -55,7 +55,7 @@ public function __construct(
$this->processors = $processors;

// This instanciates a Logger object and set it to the Registry
$this->logger = MonoLogger::getLogger($loggerName);
$this->logger = Cascade::getLogger($loggerName);
}

/**
Expand Down
18 changes: 9 additions & 9 deletions tests/MonoLoggerTest.php → tests/CascadeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
use Monolog\Logger;
use Monolog\Registry;

use Cascade\MonoLogger;
use Cascade\Cascade;
use Cascade\Tests\Fixtures;

/**
* Class MonoLoggerTest
* Class CascadeTest
*
* @author Raphael Antonmattei <[email protected]>
*/
class MonoLoggerTest extends \PHPUnit_Framework_TestCase
class CascadeTest extends \PHPUnit_Framework_TestCase
{
public function teardown()
{
Expand All @@ -22,7 +22,7 @@ public function teardown()

public function testCreateLogger()
{
$logger = MonoLogger::createLogger('test');
$logger = Cascade::createLogger('test');

$this->assertTrue($logger instanceof Logger);
$this->assertEquals('test', $logger->getName());
Expand All @@ -32,10 +32,10 @@ public function testCreateLogger()
public function testRegistry()
{
// Creates the logger and push it to the registry
$logger = MonoLogger::getLogger('test');
$logger = Cascade::logger('test');

// We should get the logger from the registry this time
$logger2 = MonoLogger::getLogger('test');
$logger2 = Cascade::logger('test');
$this->assertSame($logger, $logger2);
}

Expand All @@ -44,13 +44,13 @@ public function testRegistry()
*/
public function testRegistryWithInvalidName()
{
$logger = MonoLogger::getLogger(null);
$logger = Cascade::getLogger(null);
}

public function testFileConfig()
{
$options = Fixtures::getPhpArrayConfig();
MonoLogger::fileConfig($options);
$this->assertInstanceOf('Cascade\Config', MonoLogger::getConfig());
Cascade::fileConfig($options);
$this->assertInstanceOf('Cascade\Config', Cascade::getConfig());
}
}

0 comments on commit c136593

Please sign in to comment.