Skip to content

Commit

Permalink
feat(cli): add running type log
Browse files Browse the repository at this point in the history
  • Loading branch information
ysfscream authored and Red-Asuka committed May 23, 2024
1 parent fcf2c5f commit e8de916
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
3 changes: 1 addition & 2 deletions cli/src/lib/pub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { readFile, processPath, fileDataSplitter } from '../utils/fileUtils'
import convertPayload from '../utils/convertPayload'
import * as Debug from 'debug'
import _ from 'lodash'
import chalk from 'chalk'

const processPublishMessage = (
message: string | Buffer,
Expand Down Expand Up @@ -374,7 +373,7 @@ const multiPub = async (commandType: CommandType, options: BenchPublishOptions |

if (!verbose) {
setInterval(() => {
interactivePub.log(`Published total: ${chalk.green(total)}, message rate: ${chalk.green(rate)}/s`)
interactivePub.log(`Published total: ${total}, message rate: ${rate}/s`)
rate = 0
}, 1000)
} else {
Expand Down
22 changes: 15 additions & 7 deletions cli/src/utils/logWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ const singaleConfig = {

const signale = new Signale({
config: singaleConfig,
types: {
running: {
badge: '❯',
color: 'yellow',
label: 'Running',
},
},
})
const spinner = ora()

Expand All @@ -30,6 +37,7 @@ const logWrapper = {
warn: (msg: string) => (isLogFormat ? signale.warn(msg) : spinner.warn(msg)),
info: (msg: string) => (isLogFormat ? signale.info(msg) : spinner.info(msg)),
log: (msg: string) => signale.log(msg),
running: (msg: string) => signale.running(msg),
}

const formatValue = (value: any) => (typeof value === 'object' ? inspect(value, false, null, true) : value)
Expand Down Expand Up @@ -86,9 +94,9 @@ const benchLog = {
start: {
conn: (config: boolean | string | undefined, count: number, interval: number, host: string, port = 1883) => {
if (!config) {
logWrapper.log(`Starting connect benchmark, connections: ${count}, req interval: ${interval}ms`)
logWrapper.running(`Starting connect benchmark, connections: ${count}, req interval: ${interval}ms`)
} else {
logWrapper.log(
logWrapper.running(
`Starting connect benchmark, connections: ${count}, req interval: ${interval}ms, host: ${host}, port: ${port}`,
)
}
Expand All @@ -102,11 +110,11 @@ const benchLog = {
topic: string,
) => {
if (!config) {
logWrapper.log(
logWrapper.running(
`Starting subscribe benchmark, connections: ${count}, req interval: ${interval}ms, topic: ${topic}`,
)
} else {
logWrapper.log(
logWrapper.running(
`Starting subscribe benchmark, connections: ${count}, req interval: ${interval}ms, host: ${host}, port: ${port}, topic: ${topic}`,
)
}
Expand All @@ -122,11 +130,11 @@ const benchLog = {
message: string,
) => {
if (!config) {
logWrapper.log(
logWrapper.running(
`Starting publish benchmark, connections: ${count}, req interval: ${interval}ms, message interval: ${messageInterval}ms`,
)
} else {
logWrapper.log(
logWrapper.running(
`Starting publish benchmark, connections: ${count}, req interval: ${interval}ms, message interval: ${messageInterval}ms, host: ${host}, port: ${port}, topic: ${topic}, message: ${message}`,
)
}
Expand Down Expand Up @@ -160,7 +168,7 @@ const simulateLog = {
if (config) {
message += `, host: ${host}, port: ${port}, topic: ${topic}`
}
logWrapper.log(message)
logWrapper.running(message)
},
},
}
Expand Down

0 comments on commit e8de916

Please sign in to comment.