Path: csiph.com!eternal-september.org!feeder.eternal-september.org!border1.nntp.ams1.giganews.com!nntp.giganews.com!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!nzpost1.xs4all.net!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'handler': 0.04; 'messages.': 0.04; '(python': 0.05; 'handler,': 0.09; 'handler.': 0.09; 'logger': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'separately': 0.09; 'subject:files': 0.09; 'stored': 0.10; 'python': 0.10; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'result:': 0.16; 'something.': 0.16; 'vpn': 0.16; 'wrote:': 0.16; 'case.': 0.18; 'filtering': 0.22; 'skip:% 10': 0.22; 'am,': 0.23; 'import': 0.24; 'header:In- Reply-To:1': 0.24; 'header:User-Agent:1': 0.26; 'header:X -Complaints-To:1': 0.26; 'error': 0.27; 'logging': 0.27; 'host': 0.28; 'host.': 0.29; 'url:python': 0.33; 'info': 0.34; 'filter': 0.35; 'something': 0.35; 'level': 0.35; 'remote': 0.35; 'should': 0.36; 'url:org': 0.36; 'url:library': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'received:org': 0.37; 'missing': 0.37; 'log': 0.38; 'does': 0.39; 'to:addr:python.org': 0.40; 'your': 0.60; 'received:194': 0.61; 'charset:windows-1252': 0.62; 'thomas': 0.63; 'more': 0.63; 'here': 0.66; 'therefore': 0.67; 'levels': 0.70; 'probably,': 0.84; 'subject:From': 0.97 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: jmp Subject: Re: From logging to files to a better solution: syslog, Sentry, Logstash, .... Date: Fri, 11 Sep 2015 11:02:54 +0200 References: <5c1f52f5-59d2-48dd-b2e8-3a907a517261@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 8bit X-Gmane-NNTP-Posting-Host: paris.sequans.com User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 61 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1441962215 news.xs4all.nl 23800 [2001:888:2000:d::a6]:51712 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:96334 On 09/11/2015 09:22 AM, Thomas Güttler wrote: > > I want INFO to be logged and stored on the remote host. > Therefore I must not filter INFO messages. > > I don't want to pull INFO messages over the VPN. > > Ergo, the filtering at Python level does not help in my use case. > Or I am missing something. Probably, Your logger should have * a remote host handler * and a VPN handler. You can set filters and log levels separately for each handler. More info here https://docs.python.org/2/library/logging.html#handler-objects https://docs.python.org/2/howto/logging-cookbook.html#logging-to-multiple-destinations Something like (python 2.7) import logging logCfg = { 'remote':( logging.StreamHandler(), logging.Formatter('Remote - %(levelname)s - %(message)s'), logging.INFO, ), 'vpn':( logging.StreamHandler(), logging.Formatter('VPN - %(levelname)s - %(message)s'), logging.ERROR, ), } log = logging.getLogger() log.setLevel(logging.DEBUG) for handler, formatter, level in logCfg.itervalues(): handler.setFormatter(formatter) handler.setLevel(level) log.addHandler(handler) log.info('This is an info') log.error('This is error') and the result: Remote - INFO - This is an info VPN - ERROR - This is error Remote - ERROR - This is error JM