Skip to content

Instantly share code, notes, and snippets.

@shiumachi
Created January 6, 2014 08:49
Show Gist options
  • Save shiumachi/8279961 to your computer and use it in GitHub Desktop.
Save shiumachi/8279961 to your computer and use it in GitHub Desktop.
Hadoopのログから日付、ログレベル、メッセージを分割して返す
example = """2014-01-05 22:20:50,307 INFO org.apache.hadoop.hdfs.server.datanode.BlockPoolSliceScanner: Verification succeeded for BP-1337840909-192.168.0.1-1374311151785:blk_8462243608396789329_201176
"""
def parse_datetime_and_level(line):
""" input: hadoop log
output: [datetime, loglevel, message]
"""
import re
r = re.compile("(^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2},\d{3}) ([A-Z]{4,5}) (.*)")
m = r.match(line)
return m.groups()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment