MCPcopy Create free account
hub / github.com/tinyhttp/tinyhttp / compileArgs

Function compileArgs

packages/logger/src/index.ts:17–51  ·  view source on GitHub ↗
(
  args: (string | number)[],
  req: Request & Partial<{ originalUrl: string; ip: any }>,
  res: Response,
  options: LoggerOptions = {},
  status?: string,
  msg?: string
)

Source from the content-addressed store, hash-verified

15}
16
17const compileArgs = (
18 args: (string | number)[],
19 req: Request & Partial<{ originalUrl: string; ip: any }>,
20 res: Response,
21 options: LoggerOptions = {},
22 status?: string,
23 msg?: string
24) => {
25 const { method } = req
26 const { statusCode } = res
27
28 const url = req.originalUrl || req.url
29
30 const methods = options.methods ?? METHODS
31 const timestamp = options.timestamp ?? false
32 const emojiEnabled = options.emoji
33
34 if (methods.includes(method) && timestamp) {
35 args.push(
36 `${dayjs()
37 .format(typeof timestamp !== 'boolean' && timestamp.format ? timestamp.format : 'HH:mm:ss')
38 .toString()} - `
39 )
40 }
41
42 if (options.ip) args.push(req.ip)
43
44 if (emojiEnabled) args.push(statusEmoji[statusCode])
45
46 args.push(method)
47
48 args.push(status || res.statusCode)
49 args.push(msg || res.statusMessage)
50 args.push(url)
51}
52
53export const logger = (options: LoggerOptions = {}) => {
54 const methods = options.methods ?? METHODS

Callers 1

loggerFunction · 0.85

Calls 1

formatMethod · 0.80

Tested by

no test coverage detected