Skip to content

Commit 94579ff

Browse files
authored
Migrate src/shielding console statements to structured logger (#61081)
1 parent 4ec9185 commit 94579ff

3 files changed

Lines changed: 11 additions & 6 deletions

File tree

eslint.config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,6 @@ export default [
186186
'src/metrics/**/*.{ts,js}',
187187
'src/observability/lib/handle-package-not-found.ts',
188188
'src/search/**/*.{ts,js}',
189-
'src/shielding/**/*.{ts,js}',
190189
],
191190
rules: {
192191
'custom-rules/use-custom-logger': 'off',

src/shielding/middleware/handle-invalid-query-string-values.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import type { Response, NextFunction } from 'express'
22

3+
import { createLogger } from '@/observability/logger'
34
import { ExtendedRequest } from '@/types'
45
import statsd from '@/observability/lib/statsd'
56
import { allTools } from '@/tools/lib/all-tools'
67
import { allPlatforms } from '@/tools/lib/all-platforms'
78
import { defaultCacheControl } from '@/frame/middleware/cache-control'
89

10+
const logger = createLogger(import.meta.url)
11+
912
const STATSD_KEY = 'middleware.handle_invalid_querystring_values'
1013

1114
// Hi future reader!
@@ -46,11 +49,11 @@ export default function handleInvalidQuerystringValues(
4649
const values = Array.isArray(queryValue) ? queryValue : [queryValue]
4750
if (values.some((val) => typeof val === 'string' && !validValues.includes(val))) {
4851
if (process.env.NODE_ENV === 'development') {
49-
console.warn(
50-
'Warning! Invalid query string *value* detected. %O is not one of %O',
51-
query[key],
52+
logger.warn('Invalid query string value detected', {
53+
key,
54+
value: query[key],
5255
validValues,
53-
)
56+
})
5457
}
5558
// Some value is not recognized. Redirect to the current URL
5659
// but with that query string key removed.

src/shielding/middleware/handle-invalid-query-strings.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import type { Response, NextFunction } from 'express'
22

3+
import { createLogger } from '@/observability/logger'
34
import statsd from '@/observability/lib/statsd'
45
import { noCacheControl, defaultCacheControl } from '@/frame/middleware/cache-control'
56
import { ExtendedRequest } from '@/types'
67

8+
const logger = createLogger(import.meta.url)
9+
710
const STATSD_KEY = 'middleware.handle_invalid_querystrings'
811

912
// Exported for the sake of end-to-end tests
@@ -136,7 +139,7 @@ export default function handleInvalidQuerystrings(
136139

137140
if (keys.length >= MAX_UNFAMILIAR_KEYS_REDIRECT || badKeylessQuery || badToolsQuery) {
138141
if (process.env.NODE_ENV === 'development') {
139-
console.warn(
142+
logger.warn(
140143
'Redirecting because of a questionable query string, see https://github.com/github/docs/blob/main/src/shielding/README.md',
141144
)
142145
}

0 commit comments

Comments
 (0)