Example of how to use logging for both screen and file

Steve lonetwin at gmail.com
Wed Oct 27 14:38:19 CEST 2004

Hi Ville,
On 27 Oct 2004 15:08:16 +0300, Ville Vainio <ville at spammers.com> wrote:
> >>>>> "Steve" == Steve  <lonetwin at gmail.com> writes:
>     Steve> flog = logging.getLogger("mylog")
>     Steve> slog = logging.getLogger("mylog.slog")
> I'm a logging newbie, but -
> You shouldn't "get" loggers according to the "log name", but rather
> the application area name. I.e.
> log = logging.getLogger("myApp")
> And then add different handlers to the same log object. I.e. don't
> create several loggers, create several handlers for the same Logger
> object, as I did in the initial example of this thread (just
> substitute StreamHandler w/ sysloghandler).
      I do understand that. The code above was just an example. What I
do want is, different loggers for different areas of the application.
let me explain that.
      All the components in the system would have to log to syslog,
some components additionally would log to other places (like files).
So, for example:

core_app_logger = logger.getLogger('core')
sub_component_logger = logger.getLogger('core.sub_component')


Now, because of the way logging is designed, any message sent to
sub_component would also get handled by the core-logger's handler
(SysLogHandler). ....or so it would seem ...I still haven't got the
SysLogHandler working :(


> --
> Ville Vainio   http://tinyurl.com/2prnb
> --
> http://mail.python.org/mailman/listinfo/python-list

More information about the Python-list mailing list