Oct. 25th, 2018

jbanana: Badly drawn banana (Default)
Live apps write logs. Usually they splurge a huge amount of repetitive meaningless noise: the same thing reported again and again. Fixing things in live apps means fishing in lots of logs among all the dross for a clue as to what went wrong.

One thing that makes this hard is that different logs don't agree about the format for time stamps. These are all the same:
25-Oct-2018 16:45:00
2018-10-25 16:45:00
25/Oct/2018:16:45:00
So if I think the problem was logged at 16:45 in one of the logs, how do I search? Say hello, timepattern
#!/usr/bin/env bash
year=$1
month=$2
day=$3
hour=$4
minute=$5
case ${month} in
  1|01) mword=Jan ;;
  2|02) mword=Feb ;;
  3|03) mword=Mar ;;
  4|04) mword=Apr ;;
  5|05) mword=May ;;
  6|06) mword=Jun ;;
  7|07) mword=Jul ;;
  8|08) mword=Aug ;;
  9|09) mword=Sep ;;
    10) mword=Oct ;;
    11) mword=Nov ;;
    12) mword=Dec ;;
     *) mword=zzz ;;
esac
echo "(${day}-${mword}-${year} |${year}-${month}-${day} |${day}/${mword}/${year}:)${hour}:${minute}:"

You can use it like this:
grep -Ea "$(timepattern 2018 10 25 16 45)" $(findallthelogs)
"Search in all the logs for the messages with the right time pattern"

Windows users: install Cygwin

May 2025

M T W T F S S
   1234
5678 91011
12131415161718
19202122232425
262728293031 

Most Popular Tags

Page Summary

Style Credit

Expand Cut Tags

No cut tags
Page generated Jul. 14th, 2025 05:57 pm
Powered by Dreamwidth Studios