Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Tail Laravel logs and filter out the stack traces
tail -f -n 450 storage/logs/laravel*.log \
| grep -i -E \
"^\[\d{4}\-\d{2}\-\d{2} \d{2}:\d{2}:\d{2}\]|Next [\w\W]+?\:" \
--color
@andonovn

This comment has been minimized.

Copy link

commented Aug 19, 2018

Thanks 👍

@jsjunior

This comment has been minimized.

Copy link

commented Aug 19, 2018

+1 Thanks a lot!

@ajtrichards

This comment has been minimized.

Copy link

commented Aug 20, 2018

Awesome. Thanks for this

@sineld

This comment has been minimized.

Copy link

commented Aug 20, 2018

A bit modified for faster commands:

function log.l {
    echo "Printing contents of Laravel Log File"
    echo "Press Ctrl + C to exit"
    echo "Tip: Type 'log.c' to clear contents of Laravel Log File"
    tail -f -n 450 storage/logs/laravel*.log \
  | grep -i -E \
    "^\[\d{4}\-\d{2}\-\d{2} \d{2}:\d{2}:\d{2}\]|Next [\w\W]+?\:" \
    --color
}

function log.c {
    echo "Clearing contents of Laravel Log File"
    echo > storage/logs/laravel*.log
}
@torkiljohnsen

This comment has been minimized.

Copy link

commented Nov 29, 2018

Thought I'd try sticking this into a composer script, but can't get any output.

I have scripts/tail_laravel_log.sh:

tail -f -n 450 storage/logs/laravel*.log \
  | grep -i -E \
    "^\[\d{4}\-\d{2}\-\d{2} \d{2}:\d{2}:\d{2}\]|Next [\w\W]+?\:"

And then in composer.json:

  "scripts": {
    "logtail": [
      "./scripts/tail_laravel_log.sh"
    ]
  }

Running ./scripts/tail_laravel_log.sh works like a charm, but running composer logtail produces no output. Any ideas?

@secmohammed

This comment has been minimized.

Copy link

commented Jul 22, 2019

on opening a new tab it will check for the file Laravel log file and will throw an error that file doesn't exist, which is annoying
so I guess it would be better to check if the directory actually exists first before reading/writing from the file
NOTE: this scenario will happen if you adding these two functions two your .zshrc file or .bashrc file, so I had to add an extra condition.

function log_laravel {
    DIRECTORY=storage/logs/
    if [[ -d "$DIRECTORY" ]]; then
        echo "Printing contents of Laravel Log File"
        tail -f -n 450 storage/logs/laravel*.log \
      | grep -i -E \
        "^\[\d{4}\-\d{2}\-\d{2} \d{2}:\d{2}:\d{2}\]|Next [\w\W]+?\:" \
        --color
    fi
}

function log_clear {
    DIRECTORY=storage/logs/
    if [[ -d "$DIRECTORY" ]]; then
        echo > storage/logs/laravel*.log
    fi

}


hope this helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.