Created
August 29, 2017 19:45
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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