How to use the morgan.format function in morgan

To help you get started, we’ve selected a few morgan 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 nasa / cumulus / tf-modules / distribution / index.js View on Github external
return next();
}

distributionRouter.get('/redirect', handleRedirectRequest);
distributionRouter.get('/s3credentials', ensureAuthorizedOrRedirect, handleCredentialRequest);

const distributionApp = express();

// logging config
morgan.token('error_obj', (_req, res) => {
  if (res.statusCode !== 200) {
    return res.error;
  }
  return undefined;
});
morgan.format(
  'combined',
  '[:date[clf]] ":method :url HTTP/:http-version"'
  + ':status :res[content-length] ":referrer" ":user-agent" :error_obj'
);

// Config
distributionApp.use(boom());
distributionApp.use(morgan('combined'));
distributionApp.use(cors());
distributionApp.use(cookieParser());
distributionApp.use(bodyParser.json()); // for parsing distributionApplication/json
distributionApp.use(hsts({ maxAge: 31536000 }));

distributionApp.use('/', distributionRouter);

// global 404 response when page is not found
github nasa / cumulus / packages / api / app / index.js View on Github external
const awsServerlessExpress = require('aws-serverless-express');
const awsServerlessExpressMiddleware = require('aws-serverless-express/middleware');

const router = require('./routes');

const app = express();
app.use(awsServerlessExpressMiddleware.eventContext());

// logging config
morgan.token('error_obj', (req, res) => {
  if (res.statusCode !== 200) {
    return res.error;
  }
  return undefined;
});
morgan.format(
  'combined',
  '[:date[clf]] ":method :url HTTP/:http-version"'
  + ':status :res[content-length] ":referrer" ":user-agent" :error_obj'
);

// Config
app.use(boom());
app.use(morgan('combined'));
app.use(cors());
app.use(cookieParser());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json()); // for parsing application/json
app.use(hsts({ maxAge: 31536000 }));

// v1 routes
app.use('/v1', router);
github HackGT / checkin2 / server / app.ts View on Github external
export let app = express();

if (config.server.production) {
	app.enable("trust proxy");
}

app.use(compression());
let cookieParserInstance = cookieParser(undefined, {
	"path": "/",
	"maxAge": 1000 * 60 * 60 * 24 * 30 * 6, // 6 months
	"secure": false,
	"httpOnly": true
} as cookieParser.CookieParseOptions);
app.use(cookieParserInstance);

morgan.format("hackgt", (tokens : any, request : any, response : any) => {
        let statusColorizer: (input: string) => string = input => input; // Default passthrough function
        if (response.statusCode >= 500) {
                statusColorizer = chalk.red;
        }
        else if (response.statusCode >= 400) {
                statusColorizer = chalk.yellow;
        }
        else if (response.statusCode >= 300) {
                statusColorizer = chalk.cyan;
        }
        else if (response.statusCode >= 200) {
                statusColorizer = chalk.green;
        }

        return [
                tokens.date(request, response, "iso"),
github zhonglimh / Grunt-LiveReload / Example 2 / node_modules / grunt-contrib-connect / tasks / connect.js View on Github external
//    which enables the function to patch the default middleware without needing to know
    //    the implementation of the default middleware factory function
    var middleware;
    if (options.middleware instanceof Array) {
      middleware = options.middleware;
    } else {
      middleware = createDefaultMiddleware.call(this, connect, options);

      if (typeof(options.middleware) === 'function') {
        middleware = options.middleware.call(this, connect, options, middleware);
      }
    }

    // If --debug was specified, enable logging.
    if (grunt.option('debug') || options.debug === true) {
      morgan.format('grunt', ('[D] server :method :url :status ' +
        ':res[content-length] - :response-time ms').magenta);
      middleware.unshift(morgan('grunt'));
    }

    // Start server.
    var taskTarget = this.target;
    var keepAlive = this.flags.keepalive || options.keepalive;

    async.waterfall([
      // find a port for livereload if needed first
      function(callback){

        // Inject live reload snippet
        if (options.livereload !== false) {
          if (options.livereload === true) {
            options.livereload = 35729;
github repetere / periodicjs / lib / init / express.js View on Github external
return new Promise((resolve, reject) => {
    try {
      if (this.settings.express.config.debug) {
        morgan.token('colorstatus', morganColors);
        morgan.format('app', '\x1b[90m:remote-addr :method \x1b[37m:url\x1b[90m :colorstatus \x1b[97m:response-time ms\x1b[90m :date :referrer :user-agent\x1b[0m');
        // if (this.settings.application.status !== 'install') {
        // this.app.use(morgan('app', {
        //   format: '\x1b[90m:remote-addr :method \x1b[37m:url\x1b[90m :colorstatus \x1b[97m:response-time ms\x1b[90m :date :referrer :user-agent\x1b[0m',
        // }));
        this.app.use(morganLogger.call(this));
        // } else {
        //   app.use(morgan('app', {
        //     format: '\x1b[90m:remote-addr :method \x1b[37m:url\x1b[90m :colorstatus \x1b[97m:response-time ms\x1b[90m :date :referrer :user-agent\x1b[0m'
        //   }));
        // }
      }
      resolve(true);
    } catch (e) {
      reject(e);
    }
  });
github HackGT / registration / server / app.ts View on Github external
app.use(compression());
let cookieParserInstance = cookieParser(undefined, COOKIE_OPTIONS as cookieParser.CookieParseOptions);
app.use(cookieParserInstance);
morgan.token("sessionid", (request, response) => {
	const FAILURE_MESSAGE = "Unknown session";
	if (!request.cookies["connect.sid"]) {
		return FAILURE_MESSAGE;
	}
	let rawID: string = request.cookies["connect.sid"].slice(2);
	let id = cookieSignature.unsign(rawID, config.secrets.session);
	if (typeof id === "string") {
		return id;
	}
	return FAILURE_MESSAGE;
});
morgan.format("hackgt", (tokens, request, response) => {
	let statusColorizer: (input: string) => string = input => input; // Default passthrough function
	if (response.statusCode >= 500) {
		statusColorizer = chalk.default.red;
	}
	else if (response.statusCode >= 400) {
		statusColorizer = chalk.default.yellow;
	}
	else if (response.statusCode >= 300) {
		statusColorizer = chalk.default.cyan;
	}
	else if (response.statusCode >= 200) {
		statusColorizer = chalk.default.green;
	}

	return [
		tokens.date(request, response, "iso"),
github nasa / cumulus / packages / api / app / distribution.js View on Github external
const express = require('express');
const boom = require('express-boom');
const awsServerlessExpress = require('aws-serverless-express');
const morgan = require('morgan');
const distributionRouter = require('./distribution-routes');

const distributionApp = express();

// logging config
morgan.token('error_obj', (req, res) => {
  if (res.statusCode !== 200) {
    return res.error;
  }
  return undefined;
});
morgan.format(
  'combined',
  '[:date[clf]] ":method :url HTTP/:http-version"'
  + ':status :res[content-length] ":referrer" ":user-agent" :error_obj'
);

// Config
distributionApp.use(boom());
distributionApp.use(morgan('combined'));
distributionApp.use(cors());
distributionApp.use(cookieParser());
distributionApp.use(bodyParser.json()); // for parsing distributionApplication/json
distributionApp.use(hsts({ maxAge: 31536000 }));

distributionApp.use('/', distributionRouter);

// global 404 response when page is not found
github FGRibreau / forever-webui / app.js View on Github external
if (user.username === username) {
        return fn(null, user);
      }
    }
    return fn(null, null);
  }

  UI = new foreverUI();
  exports.forever = forever;
  exports.UI = UI;
  app = express();

  app.engine('html', ejs.renderFile);
  app.set('views', __dirname + '/views');

  morgan.format('customLog', utils.customLog);
  app.use(bodyParser.json());
  app.use(bodyParser.urlencoded({ extended: false }));
  app.use(cookieParser());
  app.use(methodOverride());
  app.use(morgan('customLog'));
  app.use(session({ 
    secret: 'c0ns0l3F0r3v3r',
    resave: false,
    saveUninitialized: false
  }));
  app.use(passport.initialize());
  app.use(passport.session());
  app.use(express.static(__dirname + '/public'));

  app.use(router);

morgan

HTTP request logger middleware for node.js

MIT
Latest version published 4 years ago

Package Health Score

76 / 100
Full package analysis