Function logger

  • Call this function at the top of your request handlers and/or middleware to obtain a logger tagged with information from the current request. For a given request, you'll always get the same logger back.

    Parameters

    • log: SimpleLoggerInterface
    • req: {
          method: string;
          path: string;
          get: ((h) => undefined | string);
          connection?: {
              remoteAddress?: string;
          };
      }
      • method: string
      • path: string
      • get: ((h) => undefined | string)
          • (h): undefined | string
          • Parameters

            • h: string

            Returns undefined | string

      • Optional connection?: {
            remoteAddress?: string;
        }
        • Optional remoteAddress?: string
    • res: {
          locals: any;
      }
      • locals: any

    Returns SimpleLoggerInterface

    Example

    export const myRequestHandler = (deps: { log: SimpleLoggerInterface }) =>
    (req: Request, res: Response, next: NextFunction) => {
    try {
    const log = logger(deps.log, req, res);
    log.info("Starting request `myRequestHandler`");
    // ...
    res.send("OK");
    } catch (e) {
    next(e);
    }
    }

Generated using TypeDoc