{"id":181,"date":"2004-11-11T08:49:21","date_gmt":"2004-11-11T16:49:21","guid":{"rendered":"http:\/\/crazedmonkey.com\/blog\/uncategorised\/colour-coding-log-output-with-sed.html"},"modified":"2006-10-19T12:32:42","modified_gmt":"2006-10-19T16:32:42","slug":"colour-coding-log-output-with-sed","status":"publish","type":"post","link":"http:\/\/crazedmonkey.com\/blog\/programming\/colour-coding-log-output-with-sed.html","title":{"rendered":"Colour-coding your log output with sed"},"content":{"rendered":"<p>If your application is logging events to a file, chances are that you often find yourself using <a href=\"http:\/\/www.gnu.org\/software\/textutils\/manual\/textutils\/html_node\/textutils_14.html\" title=\"tail invocation\">tail<\/a> to monitor that file. If you are using a logging library, chances are that your logging events are classified in differing orders of severity. Wouldn&#8217;t it be nice to make severe errors readily apparent? You can, by using <a href=\"http:\/\/www.gnu.org\/software\/sed\/sed.html\" title=\"GNU Project - Free Software Foundation (FSF) - sed\">sed<\/a>.<\/p>\n<p>If you are using a colour-aware terminal, you can <a href=\"http:\/\/consult.stanford.edu\/pub\/communications\/color-message\" title=\"Using color on a UNIX terminal\">use control codes to change the text colour<\/a>. By inserting these codes with a sed script, tail output can be colour-coded.<\/p>\n<p>For example, supposing you wanted all lines labelled as containing severe errors to be displayed in bright red. This can be accomplished using the following line:<\/p>\n<pre><code>&gt; tail -f mylog.log | sed -e \"s\/\\(.*SEVERE.*\\)\/<strong>^[<\/strong>[1;31m\\1<strong>^[<\/strong>[0m\/g\"<\/code><\/pre>\n<p>Note that <code><strong>^[<\/strong><\/code> represents the ESCAPE character, which can be typed in by pressing <code>CTRL-[<\/code> or <code>CTRL-V<\/code> followed by <code>ESC<\/code>.<\/p>\n<p>I wrote this brief tutorial because I could not find instructions specific to this topic by searching Google. No doubt a better method exists to accomplish this colour-coding, but I&#8217;m not that bright.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If your application is logging events to a file, chances are that you often find yourself using <a href=\"http:\/\/www.gnu.org\/software\/textutils\/manual\/textutils\/html_node\/textutils_14.html\" title=\"tail invocation\">tail<\/a> to monitor that file. If you are using a logging library, chances are that your logging events are classified in differing orders of severity. Wouldn&#8217;t it be nice to make severe errors readily apparent?&nbsp;&hellip;&nbsp;<a class=\"read_more\" href=\"http:\/\/crazedmonkey.com\/blog\/programming\/colour-coding-log-output-with-sed.html\" rel=\"bookmark\" title=\"Continue reading &ldquo;Colour-coding your log output with sed&rdquo;\"><span>Read more<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false},"categories":[4,2],"tags":[],"_links":{"self":[{"href":"http:\/\/crazedmonkey.com\/blog\/wp-json\/wp\/v2\/posts\/181"}],"collection":[{"href":"http:\/\/crazedmonkey.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/crazedmonkey.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/crazedmonkey.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/crazedmonkey.com\/blog\/wp-json\/wp\/v2\/comments?post=181"}],"version-history":[{"count":0,"href":"http:\/\/crazedmonkey.com\/blog\/wp-json\/wp\/v2\/posts\/181\/revisions"}],"wp:attachment":[{"href":"http:\/\/crazedmonkey.com\/blog\/wp-json\/wp\/v2\/media?parent=181"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/crazedmonkey.com\/blog\/wp-json\/wp\/v2\/categories?post=181"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/crazedmonkey.com\/blog\/wp-json\/wp\/v2\/tags?post=181"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}