[GH-ISSUE #1315] monolog add extra field is not effect #545

Closed
opened 2026-03-04 02:15:52 +03:00 by kerem · 2 comments
Owner

Originally created by @davionnini on GitHub (Apr 12, 2019).
Original GitHub issue: https://github.com/Seldaek/monolog/issues/1315

    public function __invoke(array $config)
    {
        $monolog = new Logger('my_logger');

        $monolog->pushProcessor(function ($record) {
            $record['extra']['id'] = 'hello';
            $record['extra']['app'] = 'world';
            return $record;
        });

        $output = "[%datetime%] [%extra.id%] [%extra.app%] [%level_name%] [%message%] [%context%]\n";
        $formatter = new LineFormatter($output);

        $infoFilename = config('logging.log_path').'/'.config('app.name').'/'.config('app.name').'.info';
        $infoHandler = new StreamHandler($infoFilename, Logger::INFO,false,null,false);
        $infoHandler->setFormatter($formatter);
        $monolog->pushHandler($infoHandler);

        $warningFilename = config('logging.log_path').'/'.config('app.name').'/'.config('app.name').'.warning';
        $warningHandler = new StreamHandler($warningFilename, Logger::WARNING,false,null,false);
        $warningHandler->setFormatter($formatter);
        $monolog->pushHandler($warningHandler);
        return $monolog;
    }
Originally created by @davionnini on GitHub (Apr 12, 2019). Original GitHub issue: https://github.com/Seldaek/monolog/issues/1315 ``` public function __invoke(array $config) { $monolog = new Logger('my_logger'); $monolog->pushProcessor(function ($record) { $record['extra']['id'] = 'hello'; $record['extra']['app'] = 'world'; return $record; }); $output = "[%datetime%] [%extra.id%] [%extra.app%] [%level_name%] [%message%] [%context%]\n"; $formatter = new LineFormatter($output); $infoFilename = config('logging.log_path').'/'.config('app.name').'/'.config('app.name').'.info'; $infoHandler = new StreamHandler($infoFilename, Logger::INFO,false,null,false); $infoHandler->setFormatter($formatter); $monolog->pushHandler($infoHandler); $warningFilename = config('logging.log_path').'/'.config('app.name').'/'.config('app.name').'.warning'; $warningHandler = new StreamHandler($warningFilename, Logger::WARNING,false,null,false); $warningHandler->setFormatter($formatter); $monolog->pushHandler($warningHandler); return $monolog; } ```
kerem 2026-03-04 02:15:52 +03:00
  • closed this issue
  • added the
    Support
    label
Author
Owner

@davionnini commented on GitHub (Apr 12, 2019):

I want to add some extra fields into the log, but it seems not working.

<!-- gh-comment-id:482448285 --> @davionnini commented on GitHub (Apr 12, 2019): I want to add some extra fields into the log, but it seems not working.
Author
Owner

@Seldaek commented on GitHub (Jul 2, 2019):

Config seems fine to me, can't see what the problem is sorry.

<!-- gh-comment-id:507676171 --> @Seldaek commented on GitHub (Jul 2, 2019): Config seems fine to me, can't see what the problem is sorry.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/monolog#545
No description provided.