Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the default sanic log directory to a custom directory?

Sanic currently supports Linux log directory as /dev/log, and the log wouldn't work if the directory does not exist. How do I change the directory to a custom one?

like image 930
Jibin Mathew Avatar asked Sep 09 '25 10:09

Jibin Mathew


1 Answers

Sanic uses the regular standard library logging utility.

Per the documentation:

To use your own logging config, simply use logging.config.dictConfig, or pass log_config when you initialize Sanic app.

app = Sanic('test', log_config=LOGGING_CONFIG)

# or

logging.config.dictConfig(LOGGING_CONFIG)

Here is a good resource on logging in Python.

What you are looking for is the filename keyword.

LOGGING_CONFIG = {
    ...
    'filename': '/path/to/my/log'
    ...
}
like image 126
Adam Hopkins Avatar answered Sep 11 '25 18:09

Adam Hopkins