Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #96334

Re: From logging to files to a better solution: syslog, Sentry, Logstash, ....

From jmp <jeanmichel@sequans.com>
Subject Re: From logging to files to a better solution: syslog, Sentry, Logstash, ....
Date 2015-09-11 11:02 +0200
References <5c1f52f5-59d2-48dd-b2e8-3a907a517261@googlegroups.com> <mailman.309.1441867332.8327.python-list@python.org> <e4146cbb-ce6e-47d0-9467-a585c80cac8d@googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.363.1441962215.8327.python-list@python.org> (permalink)

Show all headers | View raw


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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

From logging to files to a better solution: syslog, Sentry, Logstash, .... Thomas Güttler <hv@tbz-pariv.de> - 2015-09-09 01:33 -0700
  Re: From logging to files to a better solution: syslog, Sentry, Logstash, .... dieter <dieter@handshake.de> - 2015-09-10 08:41 +0200
    Re: From logging to files to a better solution: syslog, Sentry, Logstash, .... Thomas Güttler <hv@tbz-pariv.de> - 2015-09-11 00:22 -0700
      Re: From logging to files to a better solution: syslog, Sentry, Logstash, .... marco.nawijn@colosso.nl - 2015-09-11 01:17 -0700
        Re: From logging to files to a better solution: syslog, Sentry, Logstash, .... Thomas Güttler <hv@tbz-pariv.de> - 2015-09-15 02:37 -0700
      Re: From logging to files to a better solution: syslog, Sentry, Logstash, .... jmp <jeanmichel@sequans.com> - 2015-09-11 11:02 +0200
        Re: From logging to files to a better solution: syslog, Sentry, Logstash, .... Thomas Güttler <hv@tbz-pariv.de> - 2015-09-15 02:35 -0700
          Re: From logging to files to a better solution: syslog, Sentry, Logstash, .... jmp <jeanmichel@sequans.com> - 2015-09-15 16:36 +0200
          Re: From logging to files to a better solution: syslog, Sentry, Logstash, .... dieter <dieter@handshake.de> - 2015-09-16 07:57 +0200
            Re: From logging to files to a better solution: syslog, Sentry, Logstash, .... Thomas Güttler <hv@tbz-pariv.de> - 2015-09-16 01:31 -0700
      Re: From logging to files to a better solution: syslog, Sentry, Logstash, .... dieter <dieter@handshake.de> - 2015-09-12 08:36 +0200

csiph-web