2

This is an open ended question about logging when you have different django processes. How can I get the output of different django processes in the same log file? How would you approach this issue?

Now to my current setup. I have a django webapp running on webfaction. In django, logging is going to the console stdout

'console': {
    'class': 'logging.StreamHandler',
    'formatter': 'simple',
},

In httpd.conf it is configured to go to

ErrorLog /home/elmartus/logs/user/error_myapp.log

Then I have some jobs that get run from cron like this ./manage.py runjobs hourly that currently output to the console.

So how can I get the output of both the normal output of django and those command line processes into the same file? It would also be interesting to know how to do this with celery tasks and any other tasks that run on a separate django process.

Thanks !

Martin Massera
  • 1,718
  • 1
  • 21
  • 47
  • The simplest thing is not to log to console but to write to a log file direct. – e4c5 Jun 03 '16 at 17:08
  • 1
    Writing to the same file may garble the output of different processes, e.g. lines starting in the middle of a line being written by another process. One common approach to join logs from various processes is to write to a FIFO and then have a logger process that reads the FIFO and appends to the file. FIFO writes (that are not too big, there is a buffer maintained by the kernel) are atomic therefore log writes will not get mixed together. – grochmal Jun 03 '16 at 17:12

1 Answers1

0

look at the example from logging module docs

you can have one process called "log server" and then many applications can write to it via logging.handlers.SocketHandler

Jerzyk
  • 3,662
  • 23
  • 40