-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdlog.js
executable file
·79 lines (64 loc) · 2.48 KB
/
dlog.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env node
// © 2019 Peter Ogilvie (code@ogilvie.us.com)
const
fs = require('fs'),
child_process = require('child_process'),
createCsvWriter = require('csv-writer').createObjectCsvWriter
columnify = require('columnify'),
Program = require('pogilvie_opt'),
program = new Program(),
lgquery = 'SELECT Id, LogUser.Name, Request, Operation, Application, Status, DurationMilliseconds, LogLength FROM ApexLog'
program.version('1.0.4')
.option('-u --user <user>', 'user name or alias associated with the target org')
.option('-T --toconly', 'print table of logfiles and exit')
.parse(process.argv)
if (!program.user) {
console.log('please specify a user name for the target org (-u myOrg, --user someone@somewhere.com)')
process.exit(1)
}
const query = child_process.spawnSync('sfdx', ['force:data:soql:query', '-u', program.user, '-q', lgquery, '--json'], { encoding: 'utf-8' } )
const query_result = JSON.parse(query.stdout)
const output = [], csvout = []
if (query_result.result.done) {
const csvWriter = createCsvWriter({
path: './index.csv',
header: [
{id: 'id', title: 'ID'},
{id: 'name', title: 'NAME'},
{id: 'request', title: 'REQUEST'},
{id: 'duration', title: 'DURATION MSEC'},
{id: 'loglength', title: 'LOG LENGTH'},
{id: 'status', title: 'STATUS'}
]
});
query_result.result.records.forEach(function(r) {
output.push({
Id: r.Id,
User: r.LogUser.Name,
Request: r.Request,
Status: r.Status,
DurationMsec: r.DurationMilliseconds,
"Log Length": r.LogLength
})
csvout.push({
id: r.Id,
name: r.LogUser.Name,
request: r.Request,
status: r.Status,
duration: r.DurationMilliseconds,
loglength: r.LogLength
})
if (!program.toconly) {
let debugLog = child_process.spawnSync(
'sfdx', ['force:apex:log:get', '-u', program.user, '-i', r.Id],
{ encoding: 'utf-8' }
)
fs.writeFileSync(r.Id + '.log', debugLog.stdout, {mode: 0o664})
console.log('wrote log ' + r.Id)
}
})
console.log(columnify(output))
csvWriter.writeRecords(csvout).then(() => {
console.log('directory written to index.csv');
});
}