sanic: Custom log not working with sanic
Hi, I am using custom logger with Sanic. However, the log is neither written to file nor printing in the console. My code for logging is list below:
def create_logger(logger_name, level, filename):
logger = logging.getLogger(logger_name)
logger.setLevel(level)
fh = logging.FileHandler("./logs/"+filename)
fh.setLevel(level)
ch = logging.StreamHandler()
ch.setLevel(level)
logger.addHandler(fh)
logger.addHandler(ch)
return logger
May I know how to properly use log with Sanic, especially log to different files?
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 2
- Comments: 19 (13 by maintainers)
For me the logging seems a bit too complex. There are good ideas in it. However, it should not be necessary to learn logging for Sanic, people should just be able to use plain stdlib logging. So IMHO instead of making little fixes here and there it would be best to refactor logging to be really simple. Instead of providing a big default config which needs to be altered (and therefore known) we could maybe provide a small default config and some opt-in building blocks. – Just some thoughts without having dug into the implementation too much…
@tonyplayboy I am closing this for now. If you are still experiencing an issue with logging, please open a new issue or conversation on the community forums/
Did you take a look at examples/override_logging.py yet?
Also, specifying log files is mentioned in #721 as removed currently.
For something quick I just grab the sanic logger and use it directly e.g.:
Hope you get something working to your needs!
@yunstanford what about this:
maybe set disable_existing_loggers to False by default in LOGGING would be a better design?
Found this problem too since v0.5.2, my custom logger was working on v0.5.1.
I agree this needs to be reworked/enhanced, from a UX perspective. It should be easier to use and more intuitive. @zenixls2 @messense would either of you be interested in giving a stab at improving the usability of this?