Newbie in Python need help!
I have a file with a structure:
[timestamp] [level] [source] message
which contains following lines(for example):
[Wed Oct 11 14:34:52 2000] [error] [client 127.0.0.1] error message
[Wed Oct 11 18:56:52 2000] [warning] [client 127.0.0.1] error message
[Wed Oct 11 22:15:52 2000] [critical] [client 127.0.0.1] error message
And i need to sort this lines by [level] and display a result in STDOUT. But there is two conditions: we must have opportunity to select [level] name which uses to sorting and all lines with upper [level] should be displayed too.
[level] values:
critical = 50
error = 40
warning = 30
info = 20
debug = 10
I decide to do this with suits:
suits = {'critical': 50, 'error': 40, 'warning': 30}
l = ['critical','error','warning']
print sorted(l, key=suits.get)
But i suppose it's not the best way.
I hope you'll help me to solve this...