Regular Expressions 101

Laravel Log (MonoLog) Print

Open Workspace
  • PCRE2 (PHP)
  • Match
1

Regular Expression

/
^\[(?<ts>[\d -:]+)\] (?:\w+\.)*(?<lvl>[A-Z]+): (?<msg>[^{]*?)(?:\{"exception":(?<exception>.* (?:at (?<file>.*):(?<line>\d+))?.*)?(?<stack>\[stacktrace\].*)?\})?(?<context>\{.*\})?$
/
s

Description

Extracts the following fields from a Laravel Log print:

  • Time Stamp (Date)
  • Log Level (supports optional prefix (ie. local.DEBUG))
  • Log Message
  • Exception | Context

If an exception is detected, the file reference (file path + line number), and optional stacktrace are captured.

Submitted by Jerren