APScheduler with custom logger

1,241 views
Skip to first unread message

ssdev

unread,
Feb 13, 2014, 6:44:38 PM2/13/14
to apsch...@googlegroups.com
Hello,

I'm trying to get APScheduler to log its output (and eliminate the "no handlers configured" error, too).

All of the pages I've found simply say "use logging.basicConfig()" to set up Python logging.
I am already using a customised logger for other script output, and I'd like to route APScheduler's output through this also.

How should this be done? Can I access a scheduler's logger object and change it or something similar?


Regards.

Alex Grönholm

unread,
Feb 24, 2014, 7:04:54 PM2/24/14
to apsch...@googlegroups.com
Sorry for the delayed answer. You can access the scheduler's logger as
apscheduler.scheduler.logger (or via getLogger('apscheduler.scheduler')).
> Regards.
> --
> You received this message because you are subscribed to the Google
> Groups "APScheduler" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to apscheduler...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.

Matt McQuilty

unread,
Feb 24, 2014, 7:23:43 PM2/24/14
to apsch...@googlegroups.com
Hi Alex,

Thanks for the info - does this mean I could 'set' it to a logger that I have custom configured already with something like:
sched = apscheduler.scheduler.Scheduler()
sched.logger = my_logger
...or something else like this...?


Thanks again for your help.
Regards,

Matt.


--
Matt McQuilty
0422-45-2363


Regards.
To unsubscribe from this group and stop receiving emails from it, send an email to apscheduler+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to a topic in the Google Groups "APScheduler" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/apscheduler/sHcboAckapA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to apscheduler+unsubscribe@googlegroups.com.

Alex Grönholm

unread,
Feb 24, 2014, 7:27:20 PM2/24/14
to apsch...@googlegroups.com
25.02.2014 02:23, Matt McQuilty kirjoitti:
Hi Alex,

Thanks for the info - does this mean I could 'set' it to a logger that I have custom configured already with something like:
sched = apscheduler.scheduler.Scheduler()
sched.logger = my_logger
...or something else like this...?
That's not what I meant. Normally you want to add at least one handler for the root logger. Not having done that would cause that notification message to be displayed. How are you configuring your logging system now?


Thanks again for your help.
Regards,

Matt.


--
Matt McQuilty
0422-45-2363


On 25 February 2014 11:04, Alex Grönholm <alex.g...@nextday.fi> wrote:
14.02.2014 01:44, ssdev kirjoitti:
Hello,

I'm trying to get APScheduler to log its output (and eliminate the "no handlers configured" error, too).

All of the pages I've found simply say "use logging.basicConfig()" to set up Python logging.
I am already using a customised logger for other script output, and I'd like to route APScheduler's output through this also.

How should this be done? Can I access a scheduler's logger object and change it or something similar?

Sorry for the delayed answer. You can access the scheduler's logger as apscheduler.scheduler.logger (or via getLogger('apscheduler.scheduler')).
Regards.

--
You received this message because you are subscribed to the Google Groups "APScheduler" group.
To unsubscribe from this group and stop receiving emails from it, send an email to apscheduler...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to a topic in the Google Groups "APScheduler" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/apscheduler/sHcboAckapA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to apscheduler...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to the Google Groups "APScheduler" group.
To unsubscribe from this group and stop receiving emails from it, send an email to apscheduler...@googlegroups.com.

Matt McQuilty

unread,
Feb 24, 2014, 7:40:20 PM2/24/14
to apsch...@googlegroups.com
Hi Alex,

Currently, I have a module that returns a logger for each process which calls it:

def config_logger(level, path):
    # Setup logger
    proc_name = getproctitle()

    log_name = path + proc_name + '.log'
    logger = logging.getLogger(proc_name)
    if logger.handlers:
        for hand in logger.handlers:
            logger.removeHandler(hand)

    logger.setLevel(level)
    formatter = logging.Formatter(fmt=cfg_log.entryFormat, datefmt=cfg_log.dateFormat)
    handler = RotatingFileHandler(log_name, maxBytes=cfg_log.maxLogSize, backupCount=cfg_log.maxLogBackups)
    handler.setFormatter(formatter)
    logger.addHandler(handler)
    if cfg_log.logsShouldRotateOnKickoff:
        handler.doRollover()

    return logger


This module is imported from several process which all run independently (so they each have their own log file, etc.)
Some of these processes then use APScheduler to schedule period checks, etc...
By the time we set up a scheduler, there is already a logger object available in the process (returned from the above code)
I was hoping to just say something like:
sched.logger = self.logger
back in each process...



Regards,
Matt



--
Matt McQuilty
0422-45-2363

Alex Grönholm

unread,
Feb 24, 2014, 7:48:03 PM2/24/14
to apsch...@googlegroups.com
25.02.2014 02:40, Matt McQuilty kirjoitti:
Hi Alex,

Currently, I have a module that returns a logger for each process which calls it:

Are you sure you can't use something like logging.fileConfig() or logging.dictConfig()? Those are quite handy. Regardless, you should add some handler for the root logger.

Matt McQuilty

unread,
Feb 24, 2014, 10:16:16 PM2/24/14
to apsch...@googlegroups.com
Ah, OK - I need to re-read the documentation I think.
I thought I was configuring the root handler, by doing it in the previous code...

Thanks for your help here.

Regards,
Matt.


--
Matt McQuilty
0422-45-2363
Reply all
Reply to author
Forward
0 new messages