Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

koa-colorful-logger

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

koa-colorful-logger

A middleware for koa that can log colorful request info automatically. And you can also use it as a normal logger.

  • 0.0.3
  • unpublished
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-50%
Maintainers
1
Weekly downloads
 
Created
Source

koa-colorful-logger

A middleware for koa that can log colorful request info automatically. And you can also use it as a normal logger.

Installation

$ npm install -S koa-colorful-logger

Example

const Koa = require('koa');
const Logger = require('koa-colorful-logger');

const app = new Koa();

const logger = new Logger({
    /**
     * Should output logger info to file  
     * Default: false
     */
    output: true,
    /**
     * Where is log file in  
     * Default: `./logs`
     */
    outputDir: './logs',
    /**
     * Only when level exceed your setting will log info be output.  
     * Priority: DEBUG < INFO < WARNING < ERROR < CRITICAL
     */
    outputLevel: 'INFO',
    /**
     * The format of the prefix.  
     * Default is: '[level][time] '  
     * Available variables:
     * - [level]
     * - [time]
     */
    prefixFormat: '[level][time] ',
    /**
     * A function that should return a string for message.  
     * It will receive two args: 'ctx` and 'costTime'.  
     * Default is:  
     * ```javascript
     * function (ctx, costTime) {
     *     return `${ctx.method} ${ctx.originalUrl} - ${ctx.status} - ${costTime}ms - ${ctx.ip}`;
     * }
     * ```
     */
    msgFormatFunction: function (ctx, costTime) {
        return `${ctx.method} ${ctx.originalUrl} - ${ctx.status} - ${costTime}ms - ${ctx.ip}`;
    }
})
app.use(logger.middleware());

app.listen(4000);

Output your message.

You can use these api below to output your message.

logger.debug(msg);
logger.info(msg);
logger.warning(msg);
logger.error(msg);
logger.critical(msg);
/**
 * Param bodyColorFunc should be chalk.ChalkFunction
 */
logger.log(level, bodyColorFunc, msg);

Keywords

FAQs

Package last updated on 29 Jan 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc