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

Update logging to use Python's logging framework. #116

Open
alan404 opened this issue May 16, 2017 · 18 comments
Open

Update logging to use Python's logging framework. #116

alan404 opened this issue May 16, 2017 · 18 comments

Comments

@alan404
Copy link

alan404 commented May 16, 2017

Hi all,

I am using daphne in production environment for a chat server with around 300 concurrent users. My problem is that the daphne access log grows pretty fast (around 100MB per day) and it brings trouble when retriving log file from the remote server for checking. Is there any way to support a feature like the TimedRotatingFileHandler in python logging?

The dahpne is running under circus and the config is as below:

[watcher:daphne 1]
cmd = daphne chat.asgi.prod:channel_layer --port 8081 -b 0.0.0.0 --access-log logs/daphne1.log
numprocesses = 1
copy_env = True
...

@andrewgodwin
Copy link
Member

There is not yet - I'll leave this open for implementation as a feature. Patches are, of course, always welcome.

@andrewgodwin andrewgodwin changed the title Daphne log date rotating Log rotation Feb 2, 2018
@sourabhtk37
Copy link

Since the module is not using handlers for managing rotation of logs, should we add command line args for:

  • Size based rotation
    In this case file size have to be monitored each time while writing logs to file from access.py
  • Time based rotation
    Here we have to check the time interval difference I presume.

Views?

@andrewgodwin
Copy link
Member

I'd just go with whatever we can easily get from the Python logging module and that is relatively easy to let the user configure. What exactly that ends up being is a judgement call for the person who takes this on.

@medamines1
Copy link

Is it enough to add a check method (in access.py) inside :

def write_entry(self, host, date, request, status=None, length=None, ident=None, user=None):
if the file size exceed the size constant then we create new file and we change the self.stream at least this what i done ...

@agronick
Copy link
Contributor

agronick commented Apr 6, 2018

logrotate can be found on pretty much any Linux system. I don't think Apache or Nginx rotate their own logs. Seems like adding needless complexity.

@karolyi
Copy link
Contributor

karolyi commented May 27, 2018

Here's what can be easily done:

  • register a HUP signal listener
  • close the Logger file handle on that signal
  • rename the logfile from 'daphne.log' to 'daphne.log.1' (not sure about logrotate not already doing this)
  • on the next logging event, Logger will automatically open a new file.

Then the logs can get rotated by sending a HUP signal to the daphne PID.

I have this working in another project.

@waikup83
Copy link

waikup83 commented May 1, 2019

i push a pull request for this issues

@stoffi92
Copy link

stoffi92 commented Apr 7, 2020

Is there a special reason why daphne is not using python's logging framework for access/web logging or at least for emitting and formatting the logging entries? This may add some flexibility to daphne's logging without the need to reinvent the wheel for things like log-rotation or more sophisticated /flexible formatting of log entries.

@TraMZzz
Copy link

TraMZzz commented Nov 16, 2021

Hi, any update here?

@carltongibson
Copy link
Member

@TraMZzz Well there's #260 which is possible.

I'm not entirely convinced Daphne needs this itself. Process managers generally handle log rotation, and several of the comments here support that take.

Moving to use Python logging might be a good step.

@adamchainz
Copy link
Member

I agree, no need to add a specific log rotation feature. Process managers are the right layer to solve that at. Systemd, supervisor, etc. all do it for you.

Moving to using Python logging would be good though.

@carltongibson carltongibson changed the title Log rotation Update logging to use Python's logging framework. Nov 16, 2021
@mbidewell
Copy link

I would like to add that not using a logging framework affects more than just log rotation. In my use case we are using Docker containers in GKE. Not being able to format logs makes querying information difficult.

@Leo-tu
Copy link

Leo-tu commented Apr 26, 2023

why not use config file to config logger?

@mbidewell
Copy link

why not use config file to config logger?

The access log in the current implementation does not use the logging framework.

@turingnixstyx
Copy link

Hey is this issue still open? If yes I guess I would like to take it up

@carltongibson
Copy link
Member

@turingnixstyx There's a couple of related PRs, that I haven't had bandwidth to get to. You could have an initial look at those to see where they're at, and leave a review. We could go from there.

@turingnixstyx
Copy link

Oh cool. Could point me to some of those issues. Thanks

@carltongibson
Copy link
Member

Start with #473, linked a couple of comments up here. And then there's another one you can see if you click on the Pull Requests tab. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests