29

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?

27
+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:

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.

  • 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 Jan 13 '17 at 17:29
21

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.

  • 9
    Please read the question one more time. – Stefan Oct 6 '15 at 10:01
  • How do you get back the tabs in the log messages panel if you lose a couple? – user32882 Sep 4 '18 at 8:52
  • +1 as this is the correct answer. The comment about Stackexchange community is out of line though. – Grzegorz Oledzki Mar 6 at 20:42
8

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, privacy policy and cookie policy

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