Example of how to use logging for both screen and file

Steve lonetwin at gmail.com
Wed Oct 27 08:38:19 EDT 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')

core_app_logger.addHandler(logging.handler.SysLogHandler())
sub_component_logger.addHandler(logging.FileHandler('/tmp/sub_comp_log")

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 :(


Regards
Steve




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



More information about the Python-list mailing list