Skip to content

Commit 44e5d49

Browse files
committed
Use registry logger
1 parent f4a2778 commit 44e5d49

File tree

8 files changed

+43
-101
lines changed

8 files changed

+43
-101
lines changed

src/cli.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import { messageWithCauses, stackWithCauses } from 'pony-cause'
77
import updateNotifier from 'tiny-updater'
88
import colors from 'yoctocolors-cjs'
99

10+
import { logger } from '@socketsecurity/registry/lib/logger'
11+
1012
import { cmdAction } from './commands/action/cmd-action'
1113
import { cmdAnalytics } from './commands/analytics/cmd-analytics'
1214
import { cmdAuditLog } from './commands/audit-log/cmd-audit-log'
@@ -32,7 +34,6 @@ import { cmdThreatFeed } from './commands/threat-feed/cmd-threat-feed'
3234
import { cmdWrapper } from './commands/wrapper/cmd-wrapper'
3335
import constants from './constants'
3436
import { AuthError, InputError, captureException } from './utils/errors'
35-
import { getLogSymbols } from './utils/logging'
3637
import { meowWithSubcommands } from './utils/meow-with-subcommands'
3738

3839
const { SOCKET, rootPkgJsonPath } = constants
@@ -103,8 +104,8 @@ void (async () => {
103104
} else {
104105
errorTitle = 'Unexpected error with no details'
105106
}
106-
console.error(
107-
`${getLogSymbols().error} ${colors.bgRed(colors.white(errorTitle + ':'))} ${errorMessage}`
107+
logger.error(
108+
`${colors.bgRed(colors.white(errorTitle + ':'))} ${errorMessage}`
108109
)
109110
if (errorBody) {
110111
console.error(`\n${errorBody}`)

src/commands/logout/attempt-logout.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
import { logger } from '@socketsecurity/registry/lib/logger'
2+
13
import { applyLogout } from './apply-logout'
2-
import { logger } from '../../utils/logging'
34

45
export function attemptLogout() {
56
try {

src/commands/manifest/convert_sbt_to_maven.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import path from 'node:path'
22

33
import spawn from '@npmcli/promise-spawn'
44

5+
import { logger } from '@socketsecurity/registry/lib/logger'
56
import { Spinner } from '@socketsecurity/registry/lib/spinner'
67

78
import { safeReadFile } from '../../utils/fs'
8-
import { logger } from '../../utils/logging'
99

1010
export async function convertSbtToMaven(
1111
target: string,
@@ -76,9 +76,9 @@ export async function convertSbtToMaven(
7676
// TODO: what to do with multiple output files? Do we want to dump them to stdout? Raw or with separators or ?
7777
// TODO: maybe we can add an option to target a specific file to dump to stdout
7878
if (out === '-' && poms.length === 1) {
79-
console.log('Result:\n```')
79+
logger.log('Result:\n```')
8080
console.log(await safeReadFile(poms[0] as string, 'utf8'))
81-
console.log('```')
81+
logger.log('```')
8282
logger.success(`OK`)
8383
} else if (out === '-') {
8484
logger.error(

src/commands/report/create-report.ts

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { Spinner } from '@socketsecurity/registry/lib/spinner'
2+
import { pluralize } from '@socketsecurity/registry/lib/words'
23

34
import { handleApiCall, handleUnsuccessfulApiResponse } from '../../utils/api'
4-
import { debugLog } from '../../utils/debug'
5-
import { getLogSymbols } from '../../utils/logging'
5+
import { debugLog, isDebug } from '../../utils/debug'
66
import { getPackageFiles } from '../../utils/path-resolve'
77
import { setupSdk } from '../../utils/sdk'
88

@@ -48,32 +48,34 @@ export async function createReport(
4848
supportedFiles
4949
)
5050

51-
debugLog(
52-
'Uploading:',
53-
packagePaths.join(`\n${getLogSymbols().info} Uploading: `)
54-
)
51+
const { length: packagePathsCount } = packagePaths
5552

53+
if (packagePathsCount && isDebug()) {
54+
for (const pkgPath of packagePaths) {
55+
debugLog(`Uploading: ${pkgPath}`)
56+
}
57+
}
5658
if (dryRun) {
5759
debugLog('[dryRun] Skipped actual upload')
5860
return undefined
59-
} else {
60-
const socketSdk = await setupSdk()
61-
const spinner = new Spinner({
62-
text: `Creating report with ${packagePaths.length} package files`
63-
}).start()
61+
}
62+
const spinner = new Spinner()
63+
64+
spinner.start(
65+
`Creating report with ${packagePathsCount} package ${pluralize('file', packagePathsCount)}`
66+
)
6467

65-
const apiCall = socketSdk.createReportFromFilePaths(
66-
packagePaths,
67-
cwd,
68-
socketConfig?.issueRules
69-
)
70-
const result = await handleApiCall(apiCall, 'creating report')
68+
const apiCall = socketSdk.createReportFromFilePaths(
69+
packagePaths,
70+
cwd,
71+
socketConfig?.issueRules
72+
)
73+
const result = await handleApiCall(apiCall, 'creating report')
7174

72-
if (!result.success) {
73-
handleUnsuccessfulApiResponse('createReport', result, spinner)
74-
return undefined
75-
}
76-
spinner.successAndStop()
77-
return result
75+
if (!result.success) {
76+
handleUnsuccessfulApiResponse('createReport', result, spinner)
77+
return undefined
7878
}
79+
spinner.successAndStop()
80+
return result
7981
}

src/utils/color-or-markdown.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,17 @@ import terminalLink from 'terminal-link'
22
import colors from 'yoctocolors-cjs'
33

44
import indentString from '@socketregistry/indent-string/index.cjs'
5+
import { Logger } from '@socketsecurity/registry/lib/logger'
56

6-
import { getLogSymbols } from './logging'
7+
import type { LogSymbols } from '@socketsecurity/registry/lib/logger'
78

8-
import type { LogSymbols } from './logging'
9-
10-
const markdownLogSymbols = <LogSymbols>{
9+
const markdownLogSymbols = <LogSymbols>Object.freeze({
1110
__proto__: null,
1211
info: ':information_source:',
1312
error: ':stop_sign:',
1413
success: ':white_check_mark:',
1514
warning: ':warning:'
16-
}
15+
})
1716

1817
export class ColorOrMarkdown {
1918
public useMarkdown: boolean
@@ -77,6 +76,6 @@ export class ColorOrMarkdown {
7776
}
7877

7978
get logSymbols(): LogSymbols {
80-
return this.useMarkdown ? markdownLogSymbols : getLogSymbols()
79+
return this.useMarkdown ? markdownLogSymbols : Logger.LOG_SYMBOLS
8180
}
8281
}

src/utils/debug.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { getLogSymbols } from './logging'
1+
import { logger } from '@socketsecurity/registry/lib/logger'
2+
23
import constants from '../constants'
34

45
export function isDebug() {
@@ -8,6 +9,6 @@ export function isDebug() {
89

910
export function debugLog(...args: any[]) {
1011
if (isDebug()) {
11-
console.error(getLogSymbols().info, ...args)
12+
logger.info(...args)
1213
}
1314
}

src/utils/logging.ts

Lines changed: 0 additions & 62 deletions
This file was deleted.

src/utils/settings.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import path from 'node:path'
44
import process from 'node:process'
55

66
import config from '@socketsecurity/config'
7+
import { logger } from '@socketsecurity/registry/lib/logger'
78

89
import { safeReadFileSync } from './fs'
9-
import { logger } from './logging'
1010
import constants from '../constants'
1111

1212
const LOCALAPPDATA = 'LOCALAPPDATA'

0 commit comments

Comments
 (0)