sanic icon indicating copy to clipboard operation
sanic copied to clipboard

log to file have exception

Open ARSblithe212 opened this issue 3 years ago • 2 comments

*Describe the bug when i set backupCount=3 in log config and set workers=3 in app.run, the log content write to two file at the same time ,not writer to one file。

Code snippet

this is my log config { "version": 1, "disable_existing_loggers": false, "loggers": { "sanic.root": { "level": "DEBUG", "handlers": ["app_file"] }, "sanic.error": { "level": "DEBUG", "handlers": ["error_console", "app_file"], "propagate": true, "qualname": "sanic.error" }, "sanic.access": { "level": "DEBUG", "handlers": ["access_file", "access_console"], "propagate": true, "qualname": "sanic.access" }, "app": { "level": "DEBUG", "handlers": ["app_file", "app_console"], "propagate": true, "qualname": "app" } }, "handlers": { "console": { "class": "logging.StreamHandler", "formatter": "generic", "stream": "ext://sys.stdout" }, "error_console": { "class": "logging.StreamHandler", "formatter": "generic", "stream": "ext://sys.stderr" }, "access_console": { "class": "logging.StreamHandler", "formatter": "access", "stream": "ext://sys.stdout" }, "app_console": { "class": "logging.StreamHandler", "formatter": "generic", "stream": "ext://sys.stdout" }, "access_file": { "class": "logging.handlers.RotatingFileHandler", "formatter": "access", "filename": "./logs/access.log", "maxBytes": 10485760, "backupCount": 0 }, "app_file": { "class": "logging.handlers.RotatingFileHandler", "formatter": "generic", "filename": "./logs/app.log", "maxBytes": 10485760, "backupCount": 0 } }, "formatters": { "generic": { "format": "%(asctime)s [%(process)d] [%(levelname)s] %(message)s", "datefmt": "[%Y-%m-%d %H:%M:%S %z]", "class": "logging.Formatter" }, "access": { "format": "%(asctime)s - (%(name)s)[%(levelname)s][%(host)s]: %(request)s %(message)s %(status)d %(byte)d", "datefmt": "[%Y-%m-%d %H:%M:%S %z]", "class": "logging.Formatter" } } }

Expected behavior A clear and concise description of what you expected to happen. i want the log content write to one file not muliti file

Environment (please complete the following information):

  • OS: [e.g. iOS]
  • Version [e.g. 0.8.3] sanic=20.12.4 python=3.6.8

Additional context Add any other context about the problem here.

ARSblithe212 avatar Jul 13 '22 02:07 ARSblithe212

This looks primarily to be a question about logging and not an issue with Sanic. Regardless, I copied your config as is and it seems to work as expected with multiple workers.

  • Each worker logs access logs to ./logs/access.log
  • Each worker and the main process log everything else to ./logs/app.log

ahopkins avatar Jul 13 '22 06:07 ahopkins

This looks primarily to be a question about logging and not an issue with Sanic. Regardless, I copied your config as is and it seems to work as expected with multiple workers.

  • Each worker logs access logs to ./logs/access.log
  • Each worker and the main process log everything else to ./logs/app.log

thanks your reply. i meet the question, when i set backupCount=3 in log config and set workers=3 in app.run .the log content with different processes will write to different log file, it will not write to the same file. it seems that python logging not support mulitiproesses. Whether the problem(logging not support mulitiproesses) has been solved in sanic?

ARSblithe212 avatar Jul 13 '22 09:07 ARSblithe212