Coder Social home page Coder Social logo

Comments (5)

Seldaek avatar Seldaek commented on August 18, 2024 1

Yeah sorry but that's something you'll have to debug yourself I am afraid.. There is too much environment specific stuff at play here for me to help much.

from monolog.

Seldaek avatar Seldaek commented on August 18, 2024 1

If you figure it out please share here, it may help someone else one day

from monolog.

Seldaek avatar Seldaek commented on August 18, 2024

AFAIK there is no such limit in Monolog itself, but I am not very familiar with ECS and there might be something else there.

from monolog.

Mad4T avatar Mad4T commented on August 18, 2024

Issue happens in ECS and EKS. Also worth noting that logs from none php apps are not truncated.

from monolog.

Mad4T avatar Mad4T commented on August 18, 2024

if we ever find the reason will post it here, but we ended up doing a workaround to truncate the logs using Processor :

<?php

namespace App\Logging;

use Monolog\LogRecord;
use Monolog\Processor\ProcessorInterface;
use Throwable;

class TruncateStackTraceProcessor implements ProcessorInterface
{
    private int $traceLimit;

    public function __construct(int $traceLimit = 30)
    {
        $this->traceLimit = $traceLimit;
    }

    public function __invoke(LogRecord $record): LogRecord
    {
        $context = $record->context;
        if (isset($context['exception']) && $context['exception'] instanceof Throwable) {
            $exception = $record['context']['exception'];
            $trace = $exception->getTrace();

            if (count($trace) > $this->traceLimit) {
                $trace = array_slice($trace, 0, $this->traceLimit);
            }

            $context['exception'] = [
                'class' => get_class($record['context']['exception']),
                'message' => $record['context']['exception']->getMessage(),
                'code' => $record['context']['exception']->getCode(),
                'file' => $record['context']['exception']->getFile() . ':' . $record['context']['exception']->getLine(),
                'trace' => $this->formatStacktrace($trace),
            ];

            $record = $record->with(context: $context);
        }

        return $record;
    }

    private function formatStacktrace(array $trace): string {
        return collect($trace)
            ->map(function ($el) {
                $file = $el['file'] ?? '[unknown]';
                $line = $el['line'] ?? '[unknown]';
                $class = $el['class'] ?? '[unknown]';
                $function = $el['function'] ?? '[unknown]';
                $type = $el['type'] ?? '->';
                return "at {$class}{$type}{$function} ({$file}:{$line})";
            })
            ->join("\n");
    }
}

from monolog.

Related Issues (20)

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.