-1
2015-05-22 16:46:46,985 - __main__ - INFO - Starting to Wait for Files
2015-05-22 16:46:56,645 - __main__ - INFO - Starting: Attempt 1 Checking for New Files from gs://folder/folder/
2015-05-22 16:47:46,488 - __main__ - INFO - Success: Downloading the Files from Cloud Storage: Return Code - 0 and FileCount 1
2015-05-22 16:48:48,180 - __main__ - ERROR - Failed: Waiting for files the Files from Cloud Storage: gs://folder/folder/

I need to print every message with ERROR

Failed: Waiting for files the Files from Cloud Storage: gs://folder/folder/
...
  • Can you already show some code? You could use a regular expression for that. For example: `import re; line_contains_error = re.match('.*ERROR.*', logline)`. – Michael Hoff Dec 12 '16 at 22:15

2 Answers2

0

The solution using simple list comprehension and str.split() function:

err_mark = '- ERROR -'
with open('error.log', 'r') as fh:
    err_log = [l.split(err_mark)[1] for l in fh.readlines() if err_mark in l]

print(err_log)

The output:

[' Failed: Waiting for files the Files from Cloud Storage: gs://folder/folder/']
RomanPerekhrest
  • 88,541
  • 4
  • 65
  • 105
0
import re
lines = [line for line in in_.splitlines() if "ERROR" in line]
x = [re.sub(".+ERROR - ",'', line ) for line in lines]
print(x)
Iarwa1n
  • 460
  • 3
  • 12