53

I want to read and copypaste the error log for the crashes I am experiencing in QGIS 2.0. The error I am getting freezes QGIS so I have to ctrl-alt-del. I can see the last message in the panel, but can't copy it or scroll back to see the earlier messages. When I re-open it, the log message panel has reset to zero (QGIS starting, etc), so all the transform error messages I want are gone.

Are the older log messages written to disk somewhere?

4 Answers 4

46
+50

QGIS does not write its log messages to a file by default.

If you have a debug build (nightlies normally are) they are written to stdout. That means that if you run it in a terminal on linux you will see the messages there. On Windows I think there is a tool called Debugging Tools for Windows or similar that can intercept the messages.

An alternative is to use some minimal python scripting. Every message is emitted as a Qt signal. Therefore we can connect to these signals and write them to a file. Simply copy the following command to your python console

For QGIS 3:

from qgis.core import QgsApplication

filename = '/tmp/qgis.log'

def write_log_message(message, tag, level):
    with open(filename, 'a') as logfile:
        logfile.write('{tag}({level}): {message}'.format(tag=tag, level=level, message=message))

QgsApplication.messageLog().messageReceived.connect(write_log_message)

Or for QGIS 2:

filename = '/tmp/qgis.log'

def write_log_message(message, tag, level):
    with open(filename, 'a') as logfile:
        logfile.write('{tag}({level}): {message}'.format(tag=tag, level=level, message=message))

QgsMessageLog.instance().messageReceived.connect(write_log_message)

When you run this code, the output will be written to /tmp/qgis.log.

5
  • There should be a blank line between the end of the function definition and the final line for the Python console to be happy with the copy/paste
    – raphael
    Commented Jan 13, 2017 at 17:29
  • NameError: name 'QgsMessageLog' is not defined Commented Dec 5, 2023 at 10:49
  • @swiss_knight are you using QGIS 2 or QGIS3? Commented Dec 6, 2023 at 6:54
  • @MatthiasKuhn QGIS 3.28 or 3.34. I was told that this snippet has to be run inside the QGIS Python console. This was not clear when I was first reading your message as it is not explicitly written. But I don't see any error messages in that hand-made log file when my QGIS definitely freezes when opening a project. So I'm not able to debug it properly. Commented Dec 16, 2023 at 11:45
  • I added the import to the instructions for QGIS 3, this way it can be run from any python environment in QGIS. The error above looks very much like it's being caused by using the QGIS 2 snippet, QgsMessageLog is not used in the QGIS 3 version. In any case, there is no guarantee that QGIS will write something into the log in a specific moment, e.g. when freezing. Commented Dec 18, 2023 at 17:44
34

While this won't help with this particular problem, if you just want to see the logs during runtime (i.e. QGIS is not crashing), you can enable the Log Messages panel.

In QGIS Go to: View>Panels>Log Messages

Make sure the box is checked.

4
  • 12
    Please read the question one more time.
    – Stefan
    Commented Oct 6, 2015 at 10:01
  • 2
    How do you get back the tabs in the log messages panel if you lose a couple?
    – user32882
    Commented Sep 4, 2018 at 8:52
  • 1
    +1 as this is the correct answer. The comment about Stackexchange community is out of line though. Commented Mar 6, 2019 at 20:42
  • 1
    @GrzegorzOledzki no, the question explicitely asks persistent logs. Log messages only shows those during this runtime.
    – inc42
    Commented Jan 5, 2020 at 13:42
9

Processing => Options

You need to check this : 'Keep dialog open after running an algorithm'

after that you can copy past the error log

enter image description here

1

Might sound obvious, but I've found it useful to make the QGIS messages box a floating dialogue so that you can extend it from top to bottom of your screen. This would allow you to see and print screen more messages when QGIS crashes. Sorry, I don't know where QGIS writes these messages.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.