Skip to content

Instantly share code, notes, and snippets.

@Tynach
Created August 29, 2017 19:45
Show Gist options
  • Save Tynach/5d547605a90e71cb94ae26ec9d736b07 to your computer and use it in GitHub Desktop.
Save Tynach/5d547605a90e71cb94ae26ec9d736b07 to your computer and use it in GitHub Desktop.
Reformats PHP errors and exceptions, for old versions of PHP which were insane and inconsistent in how they were sent to Apache's logs.
#!/bin/sed -urf
# Modify timestamp format.
s/^\[\w+ \w+ \w+ ([0-9:]{8})\.[0-9]+ \w+\]( \[[^]]+\]){3}( \w+)?/[\1]/
# Hold the first timestamp.
1{
b hold
}
# Call :main manually to reset when last decision was made.
t main
{:main
# Append a newline, followed by the old timestamp.
G
# If the timestamps match, remove both.
s/^(.{11})(.*)\n(\1)$/\2/
t newlines
# If they don't match, use the new timestamp.
s/^(.{11})(.*)\n(.{11})$/\1\2/
b hold
}
# Hold the current timestamp.
{:hold
h
s/^(.{11}).*/\1/
x
}
# Replace literal '\n's with actual newlines.
{:newlines
s/\\n/\n/g
s/\n#([0-9])/\n \1./g
}
# Add whitespace to lines without a timestamp.
s/(^|\n)([^\[][^\n]*)/\1 \2/g
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment