Where to see logs of a program that crashes on Ubuntu Server?

14,119

Solution 1

If the script does not record any log by itself, this can be accomplished by redirecting standard output and error to a known file at launch. In bash use

script.py > /var/log/script.log 2>&1

The nohup utility or shell builtin may also help.

Solution 2

I find it useful to always include logging functionality (via the Python logging module) at the top of my scripts.

Here is the official Python logging doc.

Here are some good examples for various types of logging.

Share:
14,119

Related videos on Youtube

Ion
Author by

Ion

Updated on September 18, 2022

Comments

  • Ion
    Ion over 1 year

    I have been running a service (a python script using twistd library) as a non-root user that stays in the background. I've been noticing that it crashes at random times and I want to understand why. As far as I know it doesn't use any specific log file on its own, so can you tell me where I can get more information about what's going on? Either a program/application/event log file or a python-related one?

    • petrus
      petrus over 12 years
      I'm not a programmer, but could strace help?
    • Khaled
      Khaled over 12 years
      How do you know it is crashing? You can have a look at system logs /var/log/messages and /var/log/syslog.
    • Ion
      Ion over 12 years
      @Khaled I have the same script running on two systems, in one of them the script is always there (ps x) after I executed it once, in the other is not. I've been starting it again and again, it seems to run for some hours every time but next day when I login to the system to check it's not there anymore.
    • Ion
      Ion over 12 years
      @Khaled I've searched the log files you mentioned but I haven't encountered anything related to the specific script...
    • Khaled
      Khaled over 12 years
      It is a good idea to follow @S19N answer and try to run the script by redirecting output and error to a log file and see it after every while.