Skip to content

Commit 037b383

Browse files
Wrapping up log function
1 parent 514c1a5 commit 037b383

File tree

7 files changed

+131
-767
lines changed

7 files changed

+131
-767
lines changed

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ Make developing for Salesforce Commerce Cloud work with any IDE on MacOS, Window
1414
- [X] Watch for code changes and upload in background ( without being prompted for passwords )
1515
- [X] Log Viewing with Advanced Search & Filter Capabilities
1616

17-
### NOTE: THIS IS A WORK IN PROGRESS
18-
1917
Developer Overview
2018
---
2119

bin/cli.js

Lines changed: 46 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,100 +6,115 @@ const yargs = require('yargs')
66
const chalk = require('chalk')
77

88
const argv = yargs
9-
.usage('Usage: $0 <command> <client> <instance> --switches')
9+
.usage('Usage: sfcc <command> <client> <instance> --switches')
1010
.command('setup', 'Setup SFCC Development', {
1111
client: {
1212
alias: 'c',
13-
describe: 'Client Name'
13+
describe: 'Client Name',
14+
type: 'string'
1415
},
1516
hostname: {
1617
alias: 'h',
17-
describe: 'Hostname for Instance'
18+
describe: 'Hostname for Instance',
19+
type: 'string'
1820
},
1921
version: {
2022
alias: 'v',
21-
describe: 'Code Version'
23+
describe: 'Code Version',
24+
type: 'string'
2225
},
2326
directory: {
2427
alias: 'd',
25-
describe: 'Absolute path to Repository'
28+
describe: 'Absolute path to Repository',
29+
type: 'string'
2630
},
2731
username: {
2832
alias: 'u',
29-
describe: 'Your Business Manager Username'
33+
describe: 'Your Business Manager Username',
34+
type: 'string'
3035
},
3136
password: {
3237
alias: 'p',
33-
describe: 'Your Business Manager Password'
38+
describe: 'Your Business Manager Password',
39+
type: 'string'
3440
},
3541
alias: {
3642
alias: 'a',
3743
describe: 'Instance Alias',
38-
default: 'sandbox'
44+
default: 'sandbox',
45+
type: 'string'
3946
}
4047
})
4148
.command('list', 'List Configured SFCC Clients')
4249
.command('delete <client> [instance]', 'Delete Config for Client')
4350
.command('watch [client] [instance]', 'Watch for Changes and Push Updates', {
4451
log: {
4552
describe: 'Pipe Output to Log File ~/.sffc-cli.log',
53+
type: 'boolean',
4654
default: false
4755
},
4856
'errors-only': {
4957
describe: 'Only Show Notification for Errors',
58+
type: 'boolean',
5059
default: false
5160
}
5261
})
5362
.command('log [client] [instance]', 'Stream log files from an instance', {
54-
interval: {
55-
describe: 'Polling interval (seconds)',
63+
polling: {
64+
alias: 'p',
65+
describe: 'Polling Interval (seconds)',
66+
type: 'number',
5667
default: 2
5768
},
5869
lines: {
59-
describe: 'Number of lines to display',
70+
alias: 'l',
71+
describe: 'Number of Lines to Display',
72+
type: 'number',
6073
default: 100
6174
},
6275
include: {
63-
describe: 'Log levels to include',
76+
alias: 'i',
77+
describe: 'Log Types to Include',
6478
type: 'array',
6579
default: []
6680
},
6781
exclude: {
68-
describe: 'Log levels to exclude',
82+
alias: 'e',
83+
describe: 'Log Types to Exclude',
6984
type: 'array',
7085
default: []
7186
},
72-
list: {
73-
describe: 'Output a list of available log levels',
74-
default: false
75-
},
76-
dates: {
77-
describe: 'Output a list of available log dates',
78-
default: false
79-
},
8087
filter: {
81-
describe: 'Filter log messages by regexp',
88+
alias: 'f',
89+
describe: 'Filter Log Messages by RegExp',
90+
type: 'string',
8291
default: null
8392
},
84-
length: {
85-
describe: 'Length to truncate a log message',
93+
truncate: {
94+
alias: 't',
95+
describe: 'Length to Truncate Messages',
96+
type: 'number',
8697
default: null
8798
},
88-
search: {
89-
describe: 'Search all log files',
99+
list: {
100+
describe: 'Output List of Log Types',
101+
type: 'boolean',
90102
default: false
91103
},
92-
'no-timestamp': {
93-
describe: "Don't convert timestamps to local time",
104+
search: {
105+
describe: 'Search Logs with no Live Updates',
106+
type: 'boolean',
94107
default: false
95108
},
96109
latest: {
97110
describe: 'Show Latest Logs Only',
98-
boolean: false
111+
type: 'boolean',
112+
default: false
99113
}
100114
})
101-
.example('$0 delete my-client sandbox', 'Delete my-client sandbox config')
102-
.example('$0 watch my-client sandbox', 'Watch for my-client sandbox changes')
115+
.example('sfcc delete my-client sandbox', 'Delete my-client sandbox config')
116+
.example('sfcc watch my-client sandbox', 'Watch for my-client sandbox changes')
117+
.example('sfcc log -i customerror --latest', 'Watch Latest Custom Error Logs')
103118
.demand(1)
104119
.help()
105120
.version().argv

commands/log.js

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ module.exports = async options => {
4242

4343
// Group Logs
4444
let groups = groupBy(files, ({displayname}) => displayname.split('-blade')[0])
45-
let dates = groupBy(files, ({creationdate}) => creationdate.split('T')[0])
4645

4746
// pick out logs we want to include
4847
if (options.include.length > 0) {
@@ -74,7 +73,7 @@ module.exports = async options => {
7473

7574
// get list of log types
7675
if (options.list) {
77-
console.log(chalk.green.bold('\nLog Levels:\n'))
76+
console.log(chalk.green.bold('\nLog Types:\n'))
7877

7978
forEach(keys(groups).sort(), group => {
8079
console.log('· ' + group)
@@ -85,24 +84,6 @@ module.exports = async options => {
8584
process.exit()
8685
}
8786

88-
// get lost of log dates
89-
if (options.dates) {
90-
console.log(chalk.green.bold('\nLog Dates:\n'))
91-
92-
forEach(
93-
keys(dates)
94-
.sort()
95-
.reverse(),
96-
date => {
97-
console.log('· ' + date)
98-
}
99-
)
100-
101-
console.log('')
102-
103-
process.exit()
104-
}
105-
10687
// setup logs
10788
const logs = []
10889
forEach(groups, (files, name) => {

docs/usage.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,61 @@ sfcc delete <client>
5959
```
6060

6161

62+
`sfcc log`
63+
---
64+
65+
If you only have a single project, you can run:
66+
67+
```bash
68+
sfcc log
69+
```
70+
71+
If needed to setup multiple clients, or multiple instances for the same client, you will need to specify what to watch:
72+
73+
```bash
74+
sfcc log <client> <instance>
75+
```
76+
77+
**FLAGS:**
78+
79+
Name | Param | Default | Definition
80+
---------|------------|---------|----------------------------------------------
81+
Polling | `-p` | `2` | Polling Interval ( in Seconds )
82+
Lines | `-l` | `100` | Number of Existing Lines to Display
83+
Include | `-i` | | Log Types to Include ( use `sfcc log --list` for list )
84+
Exclude | `-e` | | Log Types to Exclude ( use `sfcc log --list` for list )
85+
Filter | `-f` | | Filter Log Messages that contain this string or RegExp
86+
Truncate | `-t` | | Length to Truncate Messages ( if they are too long )
87+
List | `--list` | | Output List of Log Types for `-i` & `-e`
88+
Search | `--search` | `false` | Search Logs with no Live Updates
89+
Latest | `--latest` | `false` | Show Latest Logs Only ( default is to use ALL logs )
90+
91+
#### ADVANCED USE:
92+
93+
Get current list of log types:
94+
95+
```bash
96+
sfcc log list
97+
```
98+
99+
Watch latest `customerror` logs that contain the text `PipelineCallServlet`:
100+
101+
```bash
102+
sfcc log -i customerror -l 5 -f PipelineCallServlet --latest
103+
```
104+
105+
View any `warn,error` logs that contain a matching `[0-9]{15}` RegExp pattern, and watch for new entries:
106+
107+
```bash
108+
sfcc log -i warn,error -f '[0-9]{15}'
109+
```
110+
111+
Search all latest existing logs except `staging,syslog` that contain either `WARN|ERROR` RegExp pattern:
112+
113+
```bash
114+
sfcc log -e staging,syslog -f 'WARN|ERROR' --search --latest
115+
```
116+
62117
`sfcc help`
63118
---
64119

@@ -71,5 +126,6 @@ sfcc help
71126
You can get help on a specific command by just adding `help` to the end of the command:
72127

73128
```bash
129+
sfcc log help
74130
sfcc watch help
75131
```

lib/search.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@ const truncate = require('lodash/truncate')
77
const read = require('./read')
88

99
module.exports = async (selected, groups, options) => {
10-
const text = 'Searching'
10+
const including = options.include.length > 0 ? ` '${options.include.join(', ')}'` : ''
11+
const excluding = options.exclude.length > 0 ? ` '${options.exclude.join(', ')}'` : ''
12+
const filters = options.filter.length > 0 ? ` containing '${options.filter}'` : ''
1113

14+
const text = `Searching${including}${excluding} Logs${filters} [Ctrl-C to Cancel]`
1215
const spinner = ora(text)
1316
const output = fn => {
1417
spinner.stop()
@@ -58,25 +61,25 @@ module.exports = async (selected, groups, options) => {
5861
// highlight the matching parts of the line
5962
if (options.filter) {
6063
line = line.replace(new RegExp(options.filter, 'ig'), exp => {
61-
return chalk.yellow(exp)
64+
return chalk.white.bgGreen.bold(exp)
6265
})
6366
}
6467

65-
if (options.length > 0) {
68+
if (options.truncate > 0) {
6669
line = truncate(line.trim(), {
67-
length: options.length,
68-
omission: ''
70+
length: options.truncate,
71+
omission: ''
6972
})
7073
}
7174

72-
output(() => console.log(`${chalk.white(name)} ${line}`, 'blue'))
75+
output(() => console.log(`${chalk.cyan.bold(name)} ${line}`))
7376
}
7477
}
7578
}
7679
}
7780

7881
// spinner.stop();
79-
spinner.text = `Search ` + (options.filter ? `for '${options.filter}' ` : '') + `complete`
82+
spinner.text = `Search ${including}${excluding} Logs${filters} Complete`
8083
spinner.succeed()
8184
process.exit()
8285
}

lib/tail.js

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ const truncate = require('lodash/truncate')
77
const read = require('./read')
88

99
module.exports = async (selected, logs, groups, options) => {
10-
const text = 'Streaming'
10+
const including = options.include.length > 0 ? ` '${options.include.join(', ')}'` : ''
11+
const excluding = options.exclude.length > 0 ? ` '${options.exclude.join(', ')}'` : ''
12+
const filters = options.filter.length > 0 ? ` containing '${options.filter}'` : ''
13+
14+
const text = `Streaming${including}${excluding} Logs${filters} [Ctrl-C to Cancel]`
1115
const spinner = ora(text)
1216
const output = fn => {
1317
spinner.stop()
@@ -46,28 +50,29 @@ module.exports = async (selected, logs, groups, options) => {
4650
if (options.filter && !new RegExp(options.filter).test(line)) {
4751
continue
4852
}
49-
if (options.length > 0) {
53+
if (options.truncate > 0) {
5054
line = truncate(line.trim(), {
51-
length: options.length,
52-
omission: ''
53-
})
54-
}
55-
if (!options.noTimestamp) {
56-
line = line.replace(/\[(.+)\sGMT\]/g, (exp, match) => {
57-
const date = new Date(Date.parse(match + 'Z'))
58-
return chalk.magenta(`[${date.toLocaleDateString()} ${date.toLocaleTimeString()}]`)
55+
length: options.truncate,
56+
omission: '…'
5957
})
6058
}
59+
6160
if (options.filter) {
6261
line = line.replace(new RegExp(options.filter, 'g'), exp => {
63-
return chalk.yellow(exp)
62+
return chalk.white.bgGreen.bold(exp)
6463
})
6564
}
66-
output(() => console.log(`${chalk.white(name)} ${line}`, 'blue'))
65+
66+
line = line.replace(/\[(.+)\sGMT\]/g, (exp, match) => {
67+
const date = new Date(Date.parse(match + 'Z'))
68+
return chalk.magenta(`[${date.toLocaleDateString()} ${date.toLocaleTimeString()}]`)
69+
})
70+
71+
output(() => console.log(`${chalk.cyan.bold(name)} ${line}`))
6772
}
6873
}
6974
}
7075
}
7176

72-
setTimeout(tail, options.interval * 1000)
77+
setTimeout(tail, options.polling * 1000)
7378
}

0 commit comments

Comments
 (0)