I was writing a grok pattern to parse the logs in fluentd of cinder-api, one line out which is:
2015-09-17 17:44:49.663 ^[[00;32mDEBUG oslo_concurrency.lockutils [^[[00;36m-^[[00;32m] ^[[01;35m^[[00;32mAcquired semaphore "singleton_lock"^[[00m ^[[00;33mfrom (pid=30534) lock /usr/local/lib/python2.7/dist-packages/oslo_concurrency/lockutils.py:198^[[00m
The ^[[00;32m
and other such occurrences are ASCII colour codes, which when printed in a terminal is printed like this:
I need to parse the line and am able to do it when there are no colour codes using the (tested) pattern
%{TIMESTAMP_ISO8601:timestamp}%{SPACE}%{LOGLEVEL:loglevel}%{SPACE}{NOTSPACE:api}%{SPACE}\[(?:%{DATA:request})\]%{SPACE}%{GREEDYDATA:message}
How do I modify the grok pattern so that I am able to parse the coloured log line?
I have found out the following, if it helps anyone arrive to the solution:
^[
is actually the ESC key whose octal code is \033, hex code is \x1B, decimal ASCII code is 27 and is represented by ^[ too.- There is a fluentd plugin named color-stripper that does the same but does not working for me, neither is suitable for my use case.