How to use express-pino-logger - 8 common examples

To help you get started, we’ve selected a few express-pino-logger examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github TrueCar / gluestick / packages / gluestick / src / lib / server / logger.js View on Github external
export function getLogger(middleware = false) {
  let appLogConfig = null;
  try {
    fs.statSync(`${appConfigPath}.js`);
    appLogConfig = require(appConfigPath).default.logger;
  } catch (e) {
    // no application config file yet
    appLogConfig = {};
  }
  const { logConfig, prettyConfig } = getLogConfig(appLogConfig);
  return middleware ? expressPinoLogger(logConfig, prettyConfig) : pino(logConfig, prettyConfig);
}
github alphagov / paas-admin / src / components / app / app.ts View on Github external
export default function(config: IAppConfig) {
  const app = express();

  app.use(pinoMiddleware({
    logger: config.logger,
    serializers: {
      req: (req: IncomingMessage) => ({
        method: req.method,
        url: req.url,
      }),
      res: /* istanbul ignore next */ (res: ServerResponse) => ({
        status: res.statusCode,
      }),
    },
  }));

  app.set('trust proxy', true);

  app.use(cookieSession({
    name: 'pazmin-session',
github alphagov / paas-admin / src / components / app / app.ts View on Github external
export default function(config: IAppConfig) {
  const app = express();

  app.use(pinoMiddleware({
    logger: config.logger,
    serializers: {
      req: (req: IncomingMessage) => ({
        method: req.method,
        url: req.url,
      }),
      res: /* istanbul ignore next */ (res: ServerResponse) => ({
        status: res.statusCode,
      }),
    },
  }));

  app.set('trust proxy', true);

  app.use(cookieSession({
    name: 'pazmin-session',
github gchq / CyberChef-server / app.js View on Github external
// https://helmetjs.github.io/
import helmet from "helmet";

import bakeRouter from "./routes/bake";

const app = express();
app.disable("x-powered-by");


if (process.env.NODE_ENV === "production") {
    app.use(pino({
        level: "warn"
    }));
    app.use(helmet());
} else {
    app.use(pino({
        level: "debug",
        prettyPrint: true
    }));
}

app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());


// Swagger docs
const swaggerFile = fs.readFileSync("./swagger.yml", "utf8");

// Routes
app.use("/bake", bakeRouter);
github encrypted-dev / userbase / src / userbase-server / server.js View on Github external
logger.error(`Error ${e.name}: ${e.message} in Websocket handling the following message from user ${userId}: ${msg}`)
        }

      })
    })

    setInterval(function ping() {
      wss.clients.forEach(ws => {
        if (ws.isAlive === false) return ws.terminate()

        ws.isAlive = false
        ws.ping(() => { })
      })
    }, 30000)

    app.use(expressLogger({ logger }))
    app.use(bodyParser.json())
    app.use(cookieParser())

    app.get('/api', user.authenticateUser, (req, res) =>
      req.ws
        ? res.ws(socket => wss.emit('connection', socket, req, res))
        : res.send('Not a websocket!')
    )

    app.post('/api/auth/sign-up', user.signUp)
    app.post('/api/auth/sign-in', user.signIn)
    app.post('/api/auth/sign-in-with-session', user.authenticateUser, user.extendSession)
    app.get('/api/auth/server-public-key', user.getServerPublicKey)

    app.use('/admin', express.static(path.join(__dirname + adminPanelDir)))
github encrypted-dev / userbase / src / userbase-server / server.js View on Github external
logger.error(`Error ${e.name}: ${e.message} in Websocket handling the following message from user ${userId}: ${msg}`)
        }

      })
    })

    setInterval(function ping() {
      wss.clients.forEach(ws => {
        if (ws.isAlive === false) return ws.terminate()

        ws.isAlive = false
        ws.ping(() => { })
      })
    }, 30000)

    app.use(expressLogger({ logger }))
    app.use(bodyParser.json())
    app.use(cookieParser())

    app.get('/api', user.authenticateUser, (req, res) =>
      req.ws
        ? res.ws(socket => wss.emit('connection', socket, req, res))
        : res.send('Not a websocket!')
    )

    app.post('/api/auth/sign-up', user.signUp)
    app.get('/api/auth/get-password-salts', user.getPasswordSalts)
    app.post('/api/auth/sign-in', user.signIn)
    app.post('/api/auth/sign-in-with-session', user.authenticateUser, user.extendSession)
    app.get('/api/auth/server-public-key', user.getServerPublicKey)
    app.post('/api/auth/forgot-password', user.forgotPassword)
github smartcontractkit / chainlink / explorer / src / logging.ts View on Github external
export const addRequestLogging = (app: express.Express) => {
  app.use(PinoHttp({ logger }))
}
github paularmstrong / build-tracker / src / server / src / server.ts View on Github external
import express, { Application, NextFunction, Request, RequestHandler, Response } from 'express';
import { Handlers, Queries } from './types';

export interface ServerConfig extends AppConfig {
  defaultBranch?: string;
  dev?: boolean;
  handlers?: Handlers;
  port?: number;
  setup?: () => Promise;
  queries: Queries;
  url: string;
}

const app = express();
const logger = pino();
const reqLogger = expressPino({ logger });

export const nonce = (_req: Request, res: Response, next: NextFunction): void => {
  res.locals.nonce = crypto.randomBytes(16).toString('base64');
  next();
};

export const props = (config: AppConfig, url: string): RequestHandler => (
  _req: Request,
  res: Response,
  next: NextFunction
): void => {
  res.locals.props = {
    url,
    artifactConfig: config.artifacts || {},
    hideAttribution: !!config.hideAttribution,
    name: config.name || 'Build Tracker'

express-pino-logger

An express middleware to log with pino

MIT
Latest version published 3 years ago

Package Health Score

53 / 100
Full package analysis

Popular express-pino-logger functions