Coder Social home page Coder Social logo

theorchard / monolog-cascade Goto Github PK

View Code? Open in Web Editor NEW
144.0 65.0 59.0 139 KB

Configure multiple loggers and handlers in the blink of an eye

License: MIT License

PHP 100.00%
monolog logger logging handlers formatters php processor monolog-cascade

monolog-cascade's People

Contributors

adeptofvoltron avatar cheezery avatar daniel-iwaniec avatar dbx12 avatar denizdogan avatar dmnc avatar glensc avatar hertz1 avatar jessmchung avatar jian-wu avatar kafene avatar michaelmoussa avatar rantonmattei avatar viksts avatar zhwt avatar zwiebelspaetzle avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

monolog-cascade's Issues

monolog-cascade doesn't create log folders and file

Monolog-Cascade does not create the log folder nor the log files while I configured and installed as described in the documentation. it seems to me that Handlers and Streams do not work using the conf.yaml file
Exmple with Monlog-cascade:

object(Monolog\Logger)#22 (5) {
  ["name":protected]=>
  string(16) "import"
  ["handlers":protected]=>
  array(0) {
  }
  ["processors":protected]=>
  array(0) {
  }
  ["microsecondTimestamps":protected]=>
  bool(true)
  ["exceptionHandler":protected]=>
  NULL
}

Exemple without Monolog-cascade ( using Monolog pushHandler and streamHandler )

object(Monolog\Logger)#22 (5) {
  ["name":protected]=>
  string(16) "import"
  ["handlers":protected]=>
  array(1) {
    [0]=>
    object(Monolog\Handler\StreamHandler)#49 (10) {
      ["stream":protected]=>
      NULL
      ["url":protected]=>
      string(36) "../../../../log/import.log"
      ["errorMessage":"Monolog\Handler\StreamHandler":private]=>
      NULL
      ["filePermission":protected]=>
      NULL
      ["useLocking":protected]=>
      bool(false)
      ["dirCreated":"Monolog\Handler\StreamHandler":private]=>
      NULL
      ["level":protected]=>
      int(100)
      ["bubble":protected]=>
      bool(true)
      ["formatter":protected]=>
      NULL
      ["processors":protected]=>
      array(0) {
      }
    }
  }
  ["processors":protected]=>
  array(0) {
  }
  ["microsecondTimestamps":protected]=>
  bool(true)
  ["exceptionHandler":protected]=>
  NULL
}

My conf.yaml:

formatters:
    dashed:
        class: Monolog\Formatter\LineFormatter
        format: "%datetime%-%channel%.%level_name% - %message%\n"

handlers:
    default:
        class: Monolog\Handler\StreamHandler
        level: DEBUG
        formatter: dashed
        stream: D:\TheProject\log\default.log
    import:
        class: Monolog\Handler\StreamHandler
        level: DEBUG
        formatter: dashed
        stream:  D:\TheProject\log\import.log

loggers:
    myLogger:
        handlers: [default,import]

Did I miss something ?

Support for monolog 3.5

Monolog is currently at 3.5, but monolog-cascade only supports ^2.0, are then any plans to support more recent versions of monolog?

merging configs

hi

i would like to have "dist" config and "local" configs, so most of the things, like declaring formatters, processors, handlers are done in "dist" file and loggers from "local" file

from current code reading i see Cascade::fileConfig would just overwrite self::$config, so no merging there.

PHP error: "Cannot determine default value for internal functions ..."

Example config:

handlers:
    mongodb:
        class: Monolog\Handler\MongoDBHandler
        mongo:
            class: MongoClient
            server: mongodb://example.com:27017
        database: doctrine
        collection: logs
loggers:
    doctrine:
        handlers: [mongodb]

Which results in the following error:

ReflectionException: Cannot determine default value for internal functions in /path/to/vendor/theorchard/monolog-cascade/src/Config/Loader/ClassLoader/Resolver/ConstructorResolver.php on line 105

I managed to get it working alrght:

kafene@429ebaa

I'm not sure if this is the most appropriate fix, let me know if you'd like a PR.

PHP 7.4 deprecations

NOTICE: PHP message: PHP Deprecated: Array and string offset access syntax with curly braces is deprecated in vendor/theorchard/monolog-cascade/src/Config/Loader/FileLoader/Json.php on line 54

Public property with uppercase at the beginning ends with error

This is part of my yaml file.

...
handlers:
  phpmailer_handler:
    class: MonologPHPMailer\PHPMailerHandler
    mailer:
      class: PHPMailer\PHPMailer\PHPMailer
      exceptions: true
      SMTPAuth: true
      Username: 'user'
      Password: 'password'
      isHTML: true
      isSMTP:
...

Setting Username, Password, SMTPAuth properties in following YAML ends with error:

Fatal error: Uncaught Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException: The options "password", "sMTPAuth", "username" do not exist. Defined options are: "isHTML", "isSMTP". in .....

How can i set public properties or call methods starting with uppercase letter?

Rollbar configuration example

Hello,

it is possible to use monolog-cascade to configure the rollbar handler, I would like to configure all handlers using the yml config file, but I don't know if it's possible, even using the dependency config example, now, I'm using the Rollbar handler as follows:

Cascade::fileConfig(__DIR__ . '/config/dev/log.yml');
Rollbar::init([
    'access_token' => 'supercecretaccesstoken',
    'environment' => 'development'
]);
Cascade::getLogger('daemon')->pushHandler(
    new RollbarHandler(Rollbar::logger(), \Monolog\Logger::ERROR)
);

and my config file looks like that:

formatters:
  dashed:
    class: Monolog\Formatter\LineFormatter
    format: "%datetime% - [%level_name%][%extra.process_id%] - %message%\n"
handlers:
  logfile:
    class: Monolog\Handler\StreamHandler
    level: INFO
    formatter: dashed
    processors: [memory_processor,pid_processor]
    stream: /tmp/daemon.log
processors:
  memory_processor:
    class: Monolog\Processor\MemoryUsageProcessor
  pid_processor:
    class: Monolog\Processor\ProcessIdProcessor
loggers:
  daemon:
    handlers: [logfile]

Hope you can help me.

Thanks in advance.
Diego.

Getting the streamhandler URL(s)

this link adds a getter for the streamhandler url.

I am having issues figuring out, after my $log = Cascade::getLogger('config'); , how to access the name of the file I am logging to, as a result of my (snippet) config:

           'info_file_handler' => array(
                'class' => 'Monolog\Handler\StreamHandler',
                'level' => 'INFO',
                'formatter' => 'full',
                'stream' => $logfile
                //'stream' => '/tmp/htmApp.log'
            ),

            'error_file_handler' => array(
                'class' => 'Monolog\Handler\StreamHandler',
                'level' => 'ERROR',
                'stream' => $errlogfile,
                'formatter' => 'spaced'
            )

Logging is working. When I dump the object I see the URL. How do I get it after making my logger object?

Illegal string offset 'disable_existing_loggers'

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]

"array" missing as possible param type in Cascade::fileConfig

In the PHP DocBlock for the method \Cascade\Cascade::fileConfig() "array" is missing as a valid type for $resource, as the param descriptions states.

/**
 * Load configuration options from a file or a string
 *
 * @param string $resource Path to config file or string or array
 */
public static function fileConfig($resource)
{
    self::$config = new Config($resource, new ConfigLoader());
    self::$config->load();
    self::$config->configure();
}

Maybe there should be another method which only expects an array, which is called something like "setConfig"(?)

symfony/yaml should be an optional dependency

Given that this package supports configuration in JSON and PHP arrays as well as YAML, not everyone is going to want symfony/yaml. Therefore, it should be an optional dependency.

support for 'extends' on loggers

It should be possible to extend loggers.
A extended logger should be created by the withName method from monolog.
configured handlers and processors should be added but not replacing existing stuff.

default namespace for handler

when using classname without namespace
monolog cascade should use Monolog\Handler
e.g.

class: StreamHandler

should be the same as

class: Monolog\Handler\StreamHandler

Log Rotate

Does it support rotating file? If so, what is the configuration structure enable and set $maxFiles?

Support for monolog "^2.0"?

Has it been tested on monolog latest version? If yes can you please update the composer.json accordingly?

YAML config file ignored

Cascade appears to be ignoring the config file.

I'm using the example code with a change in log level for testing (see code below). However, none of the expected behaviors are happening:

  • console messages aren't using the dashed format
  • file ./example_info.log isn't written
  • console INFO message is displayed, though log level is set to ERROR

If I intentionally set a bad path to config file, I get the expected Illegal string offset errors.

Here is my config file:

formatters:
    dashed:
        class: Monolog\Formatter\LineFormatter
        format: "%datetime%-%channel%.%level_name% - %message%\n"
handlers:
    console:
        class: Monolog\Handler\StreamHandler
        level: ERROR
        formatter: dashed
        processors: [memory_processor]
        stream: php://stdout
    info_file_handler:
        class: Monolog\Handler\StreamHandler
        level: INFO
        formatter: dashed
        stream: ./example_info.log
processors:
    web_processor:
        class: Monolog\Processor\WebProcessor
    memory_processor:
        class: Monolog\Processor\MemoryUsageProcessor
loggers:
    myLogger:
        handlers: [console, info_file_handler]
        processors: [web_processor]

and my PHP:

<?php

include 'vendor/autoload.php';

use Cascade\Cascade;

// configure your loggers
Cascade::fileConfig('config.yaml');

Cascade::getLogger('myApp')->info('Well, that works!');
Cascade::getLogger('myApp')->error('Maybe not...');

and composer.json:

{
    "require": {
        "theorchard/monolog-cascade": "^0.5.0"
    }
}

Namespaced logger configuration

Hi, guys.

I think it would be nice to have a possibility to define namespace/class loggers. So I wrote monolog-cascade-namespaced library. It allows developers to have loggers for specific classes or loggers which will log all the messages from the classes which are in some namespace etc. You know, log4j style. If you need specific logger configuration in the place where you've instantiated it - just set up needed handlers/processors for a needed logger in a config file. Otherwise, you will be given a default logger.

Just want to know your opinion on this. Do you have any plans to implement something like this directly in monolog-cascade? If yes I would get it done. The reason why I haven't made a pull-request to monolog-cascade initially is I just thought it's not more than a wrapper for configuring monolog loggers. But then I thought over and decided to suggest merging)

Handlers that require complex constructor arguments (RavenHandler) fail

I might be missing something here, but I don't seem to be able to use the closure system on constructor arguments, only on setters.

This seems to indicate that for something like the RavenHandler where I need to pass a Raven_Client I am pretty stuck.

It looks like the RedisHandler would have the same problem.

Provide functionality `Cascade::hasLogger()`

Hi,
I would like to have a function to find out if Cascade already has a logger with a given name or not. Basically just forwarding the function of Registry::hasLogger() through Cascade::hasLogger().
If you would like that, I can open a PR, I already forked the project to provide this functionality for myself but would happily provide it to the upstream.
Cheers,
DBX12

php config docs missing

The readme says it supports YAML, JSON and PHP configs, but i can't find any example or documentation how the file should be formatted, should it return array and in what structure?

I end up instead with Illegal string offset error, similar to #41

Release 0.6 pre-release with tag name that makes Composer happy

I added this comment onto the end of a closed PR which was probably, with hindsight, rather silly: #103 (comment).

Is anybody able to use the tag successfully? I'm having issues because of the branch alias at https://github.com/theorchard/monolog-cascade/blob/master/composer.json#L43

This stops anything like dev-master#0.6.0-pre from working. I can't use 0.6.0@pre because pre isn't in the composer list of stabilities.

@andymc or @mymac80 could we please have a new tag called 0.6.0-beta1? That should then allow composer to pull it in as "theorchard/monolog-cascade": "^0.6.0@beta".

Alternatively, if it's all working correctly, could it just be 0.6.0?

SwiftMailerHandler configuration

I think this is a great library making life easy in setting up logs. Although, I am trying to configure SwiftMailerHandler as one of the handlers to send alerts for errors. I am having issues in doing so. Do you have samples or documentation on how to set it up ?

Update to PHPUnit9.X to resolve PHP8 dev-dependency chain

Update to PHPUnit9.X to resolve PHP8 dev-dependency chain

See #102

EDIT: my bad, I presumed you were waiting to update until the entire project could run in PHP8. I didn't see properly the dev-master package and repo are >=7.X so next release is good-to-go.

Document how to add processor(s)?

Hi,

i see from the code that you can setup up processors,
how would you add that sort of processor with yaml configuration?

$logger = new Logger('my_logger');
$logger->pushHandler(new StreamHandler('./api.log', Logger::INFO));
$logger->pushProcessor(function ($record) {
    $record['extra']['dummy'] = 'Hello world!';

    return $record;
});

Thanks.

File permissions on handler

I believe Monolog handlers do support the $filePermission argument. However, I can't get it configured from the JSON configuration settings for a handler.

How do I pass the argument correctly so the handler will create the log file with the correct permissions?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.