简体   繁体   中英

Python syslog - view syslog messages

I'm running the following code: # create logger logger = logging.getLogger("myApp") logger.setLevel(logging.DEBUG)

# create console handler and set level to debug
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)

# add ch to logger
logger.addHandler(ch)

logger.debug('debug sample message')

Now, on a different python script, I'd like to read those messages (that belongs to "myApp", from syslog) - how can I do so???

Thanks a lot, Efrat

you can read as file :

important = []
keep_phrases = ["test",
                "important",
                "warning"]

with open("log.log" 'r') as f:
    for line in f:
        for phrase in keep_phrases:
            if phrase in line:
            important.append(line)
            print line
            break
print(important)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM