django / daphne

Django Channels HTTP/WebSocket server
BSD 3-Clause "New" or "Revised" License
2.41k stars 270 forks source link

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

Open alan404 opened 7 years ago

alan404 commented 7 years ago

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 commented 7 years ago

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

sourabhtk37 commented 6 years ago

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

Views?

andrewgodwin commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

Here's what can be easily done:

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

I have this working in another project.

waikup83 commented 5 years ago

i push a pull request for this issues

stoffi92 commented 4 years ago

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 commented 3 years ago

Hi, any update here?

carltongibson commented 3 years ago

@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 commented 3 years ago

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.

mbidewell commented 1 year ago

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 commented 1 year ago

why not use config file to config logger?

mbidewell commented 1 year ago

why not use config file to config logger?

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

turingnixstyx commented 1 year ago

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

carltongibson commented 1 year ago

@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 commented 1 year ago

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

carltongibson commented 1 year ago

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!