最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

Morgan(node.js):使用自定义格式时着色状态代码(如在'dev'中)

IT培训 admin 4浏览 0评论

Morgan(node.js):使用自定义格式时着色状态代码(如在'dev'中)

我正在使用morgan登录到node.js。

我喜欢预定义格式模式'dev'中提供的状态代码着色,但我使用的是自定义格式。

如何获得与“开发”模式下相同的颜色?

Per morgan文档,dev格式如下:

 :method :url :status :response-time ms - :res[content-length]

当我使用时它不会变色:

// does not color
app.use(morgan(':method :url :status :response-time ms - :res[content-length]')); 

但是当我使用预定义的'dev'时,它会变色!

app.use(morgan('dev'));
回答如下:

您可以很容易地使用粉笔JS进行着色。

import morgan from 'morgan';
import chalk from 'chalk'; // or you can use the require('chalk') syntax too

export const morganMiddleware = morgan(function (tokens, req, res) {
    return [
        '\n\n\n',
        chalk.hex('#ff4757').bold('            
                

Morgan(node.js):使用自定义格式时着色状态代码(如在'dev'中)

我正在使用morgan登录到node.js。

我喜欢预定义格式模式'dev'中提供的状态代码着色,但我使用的是自定义格式。

如何获得与“开发”模式下相同的颜色?

Per morgan文档,dev格式如下:

 :method :url :status :response-time ms - :res[content-length]

当我使用时它不会变色:

// does not color
app.use(morgan(':method :url :status :response-time ms - :res[content-length]')); 

但是当我使用预定义的'dev'时,它会变色!

app.use(morgan('dev'));
回答如下:

您可以很容易地使用粉笔JS进行着色。

import morgan from 'morgan';
import chalk from 'chalk'; // or you can use the require('chalk') syntax too

export const morganMiddleware = morgan(function (tokens, req, res) {
    return [
        '\n\n\n',
        chalk.hex('#ff4757').bold('                
                
            
发布评论

评论列表 (0)

  1. 暂无评论