Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nginx, Django and uwsgi logging in /opt/django/media #99

Open
flawmop opened this issue May 4, 2023 · 8 comments
Open

Nginx, Django and uwsgi logging in /opt/django/media #99

flawmop opened this issue May 4, 2023 · 8 comments
Assignees
Labels
enhancement New feature or request

Comments

@flawmop
Copy link
Member

flawmop commented May 4, 2023

In-container /opt/django/media/ doesn't seem to be the best place to be writing the Nginx and uwsgi log files, even though it's convenient if that location is being used as a docker volume.

For in-container development it may be a bit misleading that /var/log/nginx/ and /var/log/uwsgi/ exist but are not written to by default.

@flawmop
Copy link
Member Author

flawmop commented May 5, 2023

At the time of writing, uwsgi.log is 205Mb, which is getting too big to be useful, so we need a way of setting the appropriate log level according to runtime environment, e.g. at least info when running in the "production" environment, or perhaps have log rotation if possible.

This will also be true of forthcoming Nginx logs, so need to consider how can docker/client_nginx.conf and docker/client_uwsgi.ini respond to their operating environment?

Finally, also consider security implications if changing the log file permissions for uwsgi.log so we can avoid using sudo by setting it readable by other.

@flawmop
Copy link
Member Author

flawmop commented May 5, 2023

@flawmop flawmop changed the title Nginx and uwsgi logging in /opt/django/media Nginx, Django and uwsgi logging in /opt/django/media May 5, 2023
@flawmop
Copy link
Member Author

flawmop commented May 5, 2023

Discovered the following for Django logging although it only has down to DEBUG level logging unfortunately.

Can be appended to, for example, client/config/develop_settings.py.

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'formatters': {
        'verbose': {
            'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s'
        },
	'simple': {
            'format': '%(levelname)s %(message)s'
        },
    },
    'handlers': {
        'file': {
            'level': os.environ.get('LOGGING_LEVEL_DJANGO', 'DEBUG'),
            'class': 'logging.FileHandler',
            'filename': '/opt/django/media/django.log',
            'formatter': 'verbose'
        },
    },
    'root': {
        'handlers': ['file'],
        'level': os.environ.get('LOGGING_LEVEL_DJANGO', 'DEBUG'),
    },
}

https://www.freecodecamp.org/news/logging-in-python-debug-your-django-projects/
https://waltercruz.github.io/django-l10n-portuguese/topics/logging.html

@flawmop
Copy link
Member Author

flawmop commented May 11, 2023

Could also avoid logging in uwsgi/apache/etc of any requests arriving from 10.0.0.0/8 (especially 10.159.186.6) because it's probably the Nottingham Uni intranet crapfinder.

@flawmop
Copy link
Member Author

flawmop commented May 12, 2023

@MauriceHendrix
Copy link
Contributor

@flawmop what's the purpose of the ap-nimbus branch? Wouldn't it make more sense to will thill the cahnges make it to master in the client and then just catch up?
Either way let me know when you're redy for a PR. The approch seems good.

@flawmop
Copy link
Member Author

flawmop commented May 12, 2023

@flawmop what's the purpose of the ap-nimbus branch? Wouldn't it make more sense to will thill the cahnges make it to master in the client and then just catch up?

Gotta keep the documentation up-to-date! :)

@MauriceHendrix
Copy link
Contributor

@flawmop what's the purpose of the ap-nimbus branch? Wouldn't it make more sense to will thill the cahnges make it to master in the client and then just catch up?

Gotta keep the documentation up-to-date! :)

aah yes of course there is that :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants