Skip to content

Commit

Permalink
fix: adjust stega logging prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
stipsan committed Feb 8, 2024
1 parent 0917b32 commit 76a8b5e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 20 deletions.
16 changes: 7 additions & 9 deletions src/stega/stegaEncodeSourceMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ export function stegaEncodeSourceMap<Result = unknown>(
const {filter, logger, enabled} = config
if (!enabled) {
const msg = "config.enabled must be true, don't call this function otherwise"
logger?.error?.(`[@sanity/client/stega]: ${msg}`, {result, resultSourceMap, config})
logger?.error?.(`[@sanity/client]: ${msg}`, {result, resultSourceMap, config})
throw new TypeError(msg)
}

if (!resultSourceMap) {
logger?.error?.('[@sanity/client/stega]: Missing Content Source Map from response body', {
logger?.error?.('[@sanity/client]: Missing Content Source Map from response body', {
result,
resultSourceMap,
config,
Expand All @@ -39,7 +39,7 @@ export function stegaEncodeSourceMap<Result = unknown>(

if (!config.studioUrl) {
const msg = 'config.studioUrl must be defined'
logger?.error?.(`[@sanity/client/stega]: ${msg}`, {result, resultSourceMap, config})
logger?.error?.(`[@sanity/client]: ${msg}`, {result, resultSourceMap, config})
throw new TypeError(msg)
}

Expand Down Expand Up @@ -109,23 +109,21 @@ export function stegaEncodeSourceMap<Result = unknown>(
const isSkipping = report.skipped.length
const isEncoding = report.encoded.length
if (isSkipping || isEncoding) {
;(logger?.groupCollapsed || logger.log)?.(
'[@sanity/client/stega]: Encoding source map into result',
)
;(logger?.groupCollapsed || logger.log)?.('[@sanity/client]: Encoding source map into result')
logger.log?.(
`[@sanity/client/stega]: Paths encoded: ${report.encoded.length}, skipped: ${report.skipped.length}`,
`[@sanity/client]: Paths encoded: ${report.encoded.length}, skipped: ${report.skipped.length}`,
)
}
if (report.encoded.length > 0) {
logger?.log?.(`[@sanity/client/stega]: Table of encoded paths`)
logger?.log?.(`[@sanity/client]: Table of encoded paths`)
;(logger?.table || logger.log)?.(report.encoded)
}
if (report.skipped.length > 0) {
const skipped = new Set<string>()
for (const {path} of report.skipped) {
skipped.add(path.replace(reKeySegment, '0').replace(/\[\d+\]/g, '[]'))
}
logger?.log?.(`[@sanity/client/stega]: List of skipped paths`, [...skipped.values()])
logger?.log?.(`[@sanity/client]: List of skipped paths`, [...skipped.values()])
}

if (isSkipping || isEncoding) {
Expand Down
22 changes: 11 additions & 11 deletions test/stega/__snapshots__/stegaEncodeSourceMap.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ exports[`GraphQL API > logger.error 1`] = `[]`;
exports[`GraphQL API > logger.log 1`] = `
[
[
"[@sanity/client/stega]: Encoding source map into result",
"[@sanity/client]: Encoding source map into result",
],
[
"[@sanity/client/stega]: Paths encoded: 2, skipped: 0",
"[@sanity/client]: Paths encoded: 2, skipped: 0",
],
[
"[@sanity/client/stega]: Table of encoded paths",
"[@sanity/client]: Table of encoded paths",
],
]
`;
Expand Down Expand Up @@ -70,16 +70,16 @@ exports[`resolveEditUrl '/' > logger.error 1`] = `[]`;
exports[`resolveEditUrl '/' > logger.log 1`] = `
[
[
"[@sanity/client/stega]: Encoding source map into result",
"[@sanity/client]: Encoding source map into result",
],
[
"[@sanity/client/stega]: Paths encoded: 18, skipped: 81",
"[@sanity/client]: Paths encoded: 18, skipped: 81",
],
[
"[@sanity/client/stega]: Table of encoded paths",
"[@sanity/client]: Table of encoded paths",
],
[
"[@sanity/client/stega]: List of skipped paths",
"[@sanity/client]: List of skipped paths",
[
"description[]._key",
"description[]._type",
Expand Down Expand Up @@ -224,16 +224,16 @@ exports[`resolveEditUrl 'https://test.sanity.studio' > logger.error 1`] = `[]`;
exports[`resolveEditUrl 'https://test.sanity.studio' > logger.log 1`] = `
[
[
"[@sanity/client/stega]: Encoding source map into result",
"[@sanity/client]: Encoding source map into result",
],
[
"[@sanity/client/stega]: Paths encoded: 18, skipped: 81",
"[@sanity/client]: Paths encoded: 18, skipped: 81",
],
[
"[@sanity/client/stega]: Table of encoded paths",
"[@sanity/client]: Table of encoded paths",
],
[
"[@sanity/client/stega]: List of skipped paths",
"[@sanity/client]: List of skipped paths",
[
"description[]._key",
"description[]._type",
Expand Down

0 comments on commit 76a8b5e

Please sign in to comment.