theorchard / monolog-cascade

Configure multiple loggers and handlers in the blink of an eye
MIT License
145 stars 62 forks source link

Illegal string offset 'disable_existing_loggers' #41

Closed mdeletrez closed 8 years ago

mdeletrez commented 8 years ago

Illegal string offset 'disable_existing_loggers' in vendor/theorchard/monolog-cascade/src/Config.php:99

$this->options seems to be a string having the path of the config file

        $path = APPLICATION_PATH . '/configs/monolog/cascade/testcontroller.yaml';
        //echo $path."\n";
        Cascade::fileConfig($path);

        Cascade::getLogger('myApp')->info('Well, that works!');
        Cascade::getLogger('myApp')->error('Maybe not...');
formatters:
    dashed:
        class: Monolog\Formatter\LineFormatter
        format: "%datetime%-%channel%.%level_name% - %message%\n"
handlers:
    console:
        class: Monolog\Handler\StreamHandler
        level: DEBUG
        formatter: dashed
        stream: php://stdout
    info_file_handler:
        class: Monolog\Handler\StreamHandler
        level: INFO
        formatter: dashed
        stream: /tmp/example_info.log
processors:
    introspection_processor:
        class: Monolog\Processor\IntrospectionProcessor
loggers:
    myApp:
        handlers: [console, info_file_handler]
        processors: [introspection_processor]
mdeletrez commented 8 years ago

sorry i make a mistake about name of my file xxxx.yaml whereas the extension was xxx.yml

so your test file_exists doesn't work ... i should put it in my code :

try {
            $path = APPLICATION_PATH . '/configs/monolog/cascade/testcontroller.yml';
            //echo $path."\n";
            if (!file_exists($path)) {
                throw new Exception('file not exists : '.$path);
            }
            Cascade::fileConfig($path);

            Cascade::getLogger('myApp')->info('Well, that works!');
            Cascade::getLogger('myApp')->error('Maybe not...');
        } catch (Exception $e) {
            echo $e;
        }
rantonmattei commented 8 years ago

So, I'm not sure I follow. Do you need any help?

glensc commented 8 years ago

@rantonmattei he says that your Cascade::fileConfig($path); does not check that file does not exist and proceeds with uncertain error message that does not give any hint what was wrong.

glensc commented 8 years ago

run this example:

<?php
use Cascade\Cascade;
require 'vendor/autoload.php';
Cascade::fileConfig('no-such-file-anywhere');

and you get:

$ php test.php

PHP Warning:  Illegal string offset 'disable_existing_loggers' in monolog-cascade/src/Config.php on line 99
PHP Stack trace:
PHP   1. {main}() monolog-cascade/test.php:0
PHP   2. Cascade\Cascade::fileConfig() monolog-cascade/test.php:7
PHP   3. Cascade\Config->configure() monolog-cascade/src/Cascade.php:112
PHP Warning:  Illegal string offset 'disable_existing_loggers' in monolog-cascade/src/Config.php on line 102
PHP Stack trace:
PHP   1. {main}() monolog-cascade/test.php:0
PHP   2. Cascade\Cascade::fileConfig() monolog-cascade/test.php:7
PHP   3. Cascade\Config->configure() monolog-cascade/src/Cascade.php:112
PHP Fatal error:  Uncaught exception 'RuntimeException' with message 'Cannot configure loggers. No logger configuration options provided.' in monolog-cascade/src/Config.php:121
Stack trace:
#0 monolog-cascade/src/Cascade.php(112): Cascade\Config->configure()
#1 monolog-cascade/test.php(7): Cascade\Cascade::fileConfig('no-such-file-an...')
#2 {main}
thrown in monolog-cascade/src/Config.php on line 121