You don't name a use case, or whether there is a particular place you are integrating this from. But if it was just a matter of, "I need to get a log out and check for some string value in it," these days, I would probably prefer to use Salesforce DX to do this.
sfdx force:apex:log:get -i <MyLogId>
Using this you can also retrieve multiple logs at once...potentially all of them.
sfdx force:apex:log:get -n 2 <- retrieve the last 2 log files
sfdx force:apex:log:get -n 10
This will spit out all of the log bodies which you can then grep.
sfdx force:apex:log:get -n 2 | grep 'Colonial'
18:46:16.10 (20641304)|VARIABLE_ASSIGNMENT|[2]|p|{"Id":"a040E000001zVStQAM","Name":"Stunning Colonial","Location__c":"API location: [42.360642 -71.110448]"}|0x5cacdf1b
18:46:35.11 (17502936)|VARIABLE_ASSIGNMENT|[2]|p|{"Id":"a040E000001zVStQAM","Name":"Stunning Colonial","Location__c":"API location: [42.360642 -71.110448]"}|0x37955bc2
If you want context around the actual line you find, you can use grep
's before and after context features to get more than just the line you are looking for. For instance here, I get the line with the regex pattern, and 5 lines before and after each time it is found.
sfdx force:apex:log:get -n 2 | grep -B 5 -A 5 'Colonial'
18:46:35.11 (17280734)|STATEMENT_EXECUTE|[2]
18:46:35.11 (17333161)|USER_DEBUG[2]|DEBUG|System.Location[getLatitude=42.335435;getLongitude=-71.106827;]
18:46:35.11 (17362725)|HEAP_ALLOCATE|[2]|Bytes:5
18:46:35.11 (17384098)|HEAP_ALLOCATE|[2]|Bytes:16
18:46:35.11 (17396491)|VARIABLE_SCOPE_BEGIN|[2]|p|Property__c|true|false
18:46:35.11 (17502936)|VARIABLE_ASSIGNMENT|[2]|p|{"Id":"a040E000001zVStQAM","Name":"Stunning Colonial","Location__c":"API location: [42.360642 -71.110448]"}|0x37955bc2
18:46:35.11 (17517639)|STATEMENT_EXECUTE|[2]
18:46:35.11 (17520423)|STATEMENT_EXECUTE|[2]
18:46:35.11 (17566892)|USER_DEBUG|[2]|DEBUG|System.Location[getLatitude=42.360642;getLongitude=-71.110448;]
18:46:35.11 (17597445)|HEAP_ALLOCATE|[2]|Bytes:5
18:46:35.11 (17616068)|HEAP_ALLOCATE|[2]|Bytes:16
--
--
18:56:25.19 (29745072)|STATEMENT_EXECUTE|[2]
18:56:25.19 (29815343)|USER_DEBUG|[2]|DEBUG|System.Location[getLatitude=42.335435;getLongitude=-71.106827;]
18:56:25.19 (29877304)|HEAP_ALLOCATE|[2]|Bytes:5
18:56:25.19 (29908067)|HEAP_ALLOCATE|[2]|Bytes:16
18:56:25.19 (29923611)|VARIABLE_SCOPE_BEGIN|[2]|p|Property__c|true|false
18:56:25.19 (30106839)|VARIABLE_ASSIGNMENT|[2]|p|{"Id":"a040E000001zVStQAM","Name":"Stunning Colonial","Location__c":"API location: [42.360642 -71.110448]"}|0x380f42d
18:56:25.19 (30131234)|STATEMENT_EXECUTE|[2]
18:56:25.19 (30135912)|STATEMENT_EXECUTE|[2]
18:56:25.19 (30215204)|USER_DEBUG|[2]|DEBUG|System.Location[getLatitude=42.360642;getLongitude=-71.110448;]
18:56:25.19 (30269076)|HEAP_ALLOCATE|[2]|Bytes:5
18:56:25.19 (30294622)|HEAP_ALLOCATE|[2]|Bytes:16