How to export debug logs?

All we need is an easy explanation of the problem, so here it is.

I spend my days waiting on the Force.com Console and it makes me crazy, I have a pretty nice machine and it still chokes on the details sometimes.

Anyways, I saw Loggly had given a presentation at DF ’11 and is presenting again this year Dreamforce ’12.

However, it seems like they’re presentation is targeted at using their product, or for that matter others like it (SumoLogic, Splunk) on Heroku, and not really targeting APEX/VisualForce development!

Is this the case? Are there any better solutions out there for reviewing logs?

Are there any APIs that allow you to export your debug logs out of SFDC programatically? Or has anyone even tried to tackle this?

How to solve :

I know you bored from this bug, So we are here to help you! Take a deep breath and look at the explanation of your problem. We have many solutions to this problem, But we recommend you to use the first method because it is tested & true method that will 100% work for you.

Method 1

I’ve been working on a tool that allows you to export the apex logs and then gives you some basic highlighting, searching and filtering options. I often end up working with logs closer to 2 MB in size and needed a way to quickly filter out just the USER_DEBUG messages.

FuseIT SFDC Explorer is .NET based and currently only runs on Windows. It is still in beta (the kind of beta where there are still sharp edges that you could cut yourself on. I.e. don’t be surprised if it crashes occasionally).

The screen shots on the web site are a bit out of date. What I often do is bring the Force.com console up to ensure that it is polling and capturing the logs. Then I can use the Refresh and Open Log buttons on the Apex Logs tab to open up the required log.

FuseIT SFDC Explorer

Once you have a log open you can use the checkboxes in the left Apex Log area to show/hide only certain events. Alternatively, you can right click on an event in the log to hide it from there.

FuseIT SFDC Explorer Toggle Raw/Grid Log

If you just want a quick way to download the raw log then you can toggle the view to just show the log text. There is a copy log to clipboard button if you just want to grab the whole thing to paste into the editor of your choice. The paste allows you to drop in partial logs or logs copied out of Force.com explorer.

Method 2

Agreed that the ExtJS console needs a lot of work. anything halfway complex will bring the interface to its knees. I have settled into a groove of running unit tests from the website and downloading the log, or copying and pasting the raw log into Notepad++, once there its a 2 click operation to find the lines with this regular expression “USER_DEBUG|FATAL|MAXIMUM DEBUG|Op:|SOQL_EXECUTE_BEGIN|SOQL_EXECUTE_END” and then press “Find All in Current Document”

That brings up a list of matching lines below that you can double click on to navigate through the log without making your eyes bleed.

Search "USER_DEBUG|FATAL|MAXIMUM DEBUG|Op:|SOQL_EXECUTE_BEGIN|SOQL_EXECUTE_END" (505 hits in 1 files)
C:\Downloads\apex (33).log (505 hits)
Line 208: 00:06:53.652 (6652739000)|USER_DEBUG|[13]|DEBUG|org: 00DM0000000Br5EMAS
Line 261: 00:06:53.698 (6698356000)|USER_DEBUG|[67]|DEBUG|setting ProjectID = 21060077

Method 3

What browser are you using?

I gave up using anything other than Chrome with the Developer Console. It’s the only browser that I got any sort of decent response.

It still can be a bit glitchy now and then, but it’s hands down better than IE or FF performance.

As for exporting your debug logs – There’s no Download option anymore (sigh)… I did find that if you select the desired log and then click the “Open Raw Log” button you get a version that will copy and paste nicely into Notepad++

I often do this for the big logs simply because it’s more responsive to my filter and search requests.

Method 4

I’m going to post this to one other question. But here’s a quick script that downloads all logs to a “log” subdirectory.

#!/bin/bash

# script for export ALL debug logs to a subdirectory
# named "log".  
#
# it requires the "force" CLI tool be available and
# assumes the user is already logged in.
#
# Sure, I could have added more debugging, like checking
# to see if the user was logged in, but I didn't have 
# all night. ;-)
#
# 2017-08-29 [email protected]

for each in $(force query "select id from apexlog"); do
    log=$(echo $each | sed -e 's/"//g')

    if [ "$log" == "Id" ]; then
        echo "ignoring $log"
        continue
    fi

    echo "writing log/$log.debug"
    force log $log > log/$log.debug
done

Method 5

I use Sublime Text 2 with a customized plugin.

https://github.com/mdenavacelle/SublimeApexLogReader

Grabs all debug logs with a keyboard shortcut.

Method 6

Now can be done in Visual Studio Code with the Salesforce Extension Pack installed, just select “SFDX: Get Apex Debug Logs” from the command palette.

VS Code Screenshot

Method 7

Now we can download logs from Logs window in dev console. Right-click on any log in Logs section on bottom side and it gives an option to open the raw file or to download log.

Method 8

I’m a part of a team that has been working on Maven Tools for Salesforce, a Google Chrome extension that offers you a collection of Salesforce developer tools and it can help you with this issue.

With Maven Tools you can open, search, delete and export multiple apex debug logs at once. As you can see in the screenshot below, you can select multiple logs and export them by clicking the export button. Logs will be exported in a zip file with each log being exported into a separate .txt file.

How to export debug logs?

Note: Use and implement method 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply