Django file logging - rotate files on every day and max file size

1,716 views
Skip to first unread message

Arulselvam K

unread,
Dec 8, 2019, 3:07:37 AM12/8/19
to django...@googlegroups.com
Hi,

How do we configure log settings so that every day generates new log file and also based on max file size?

I am able to use "RotatingFileHandler" to rotates files based on max file size with following settings.
'handlers': {
'file': {
'level': 'DEBUG',
'backupCount': 10, # how many backup file to keep, 10 days
'class': 'logging.handlers.RotatingFileHandler',
'filename': '/home/iness/logs/vconnect.log',
'maxBytes': 1024*1024*1, # 1MB
'backupCount': 10,
'formatter': 'standard'
},
}

Franz Ulenaers

unread,
Dec 8, 2019, 3:44:15 AM12/8/19
to Django users
i get a problem with the 'formatter' : 'standard'
Watching for file changes with StatReloader
Exception in thread django-main-thread:
Traceback (most recent call last):
  File "/usr/lib/python3.7/logging/config.py", line 700, in configure_handler
    formatter = self.config['formatters'][formatter]
  File "/usr/lib/python3.7/logging/config.py", line 324, in __getitem__
    value = dict.__getitem__(self, key)
KeyError: 'standard'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/lib/python3.7/logging/config.py", line 563, in configure
    handler = self.configure_handler(handlers[name])
  File "/usr/lib/python3.7/logging/config.py", line 703, in configure_handler
    '%r' % formatter) from e
ValueError: Unable to set formatter 'standard'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/lib/python3.7/threading.py", line 926, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.7/threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/local/lib/python3.7/dist-packages/django/utils/autoreload.py", line 54, in wrapper
    fn(*args, **kwargs)
  File "/usr/local/lib/python3.7/dist-packages/django/core/management/commands/runserver.py", line 109, in inner_run
    autoreload.raise_last_exception()
  File "/usr/local/lib/python3.7/dist-packages/django/utils/autoreload.py", line 77, in raise_last_exception
    raise _exception[1]
  File "/usr/local/lib/python3.7/dist-packages/django/core/management/__init__.py", line 337, in execute
    autoreload.check_errors(django.setup)()
  File "/usr/local/lib/python3.7/dist-packages/django/utils/autoreload.py", line 54, in wrapper
    fn(*args, **kwargs)
  File "/usr/local/lib/python3.7/dist-packages/django/__init__.py", line 19, in setup
    configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
  File "/usr/local/lib/python3.7/dist-packages/django/utils/log.py", line 76, in configure_logging
    logging_config_func(logging_settings)
  File "/usr/lib/python3.7/logging/config.py", line 800, in dictConfig
    dictConfigClass(config).configure()
  File "/usr/lib/python3.7/logging/config.py", line 571, in configure
    '%r' % name) from e
ValueError: Unable to configure handler 'file'


Op zondag 8 december 2019 09:07:37 UTC+1 schreef Arulselvam K:

Franz Ulenaers

unread,
Dec 8, 2019, 3:52:16 AM12/8/19
to Django users
it works when i remove the formatter line !

Op zondag 8 december 2019 09:44:15 UTC+1 schreef Franz Ulenaers:
Reply all
Reply to author
Forward
0 new messages