惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

The GitHub Blog
The GitHub Blog
博客园_首页
T
Threatpost
S
Secure Thoughts
月光博客
月光博客
S
Schneier on Security
爱范儿
爱范儿
C
CXSECURITY Database RSS Feed - CXSecurity.com
阮一峰的网络日志
阮一峰的网络日志
Microsoft Azure Blog
Microsoft Azure Blog
L
LINUX DO - 热门话题
C
Cyber Attacks, Cyber Crime and Cyber Security
大猫的无限游戏
大猫的无限游戏
Cyberwarzone
Cyberwarzone
Blog — PlanetScale
Blog — PlanetScale
A
About on SuperTechFans
F
Fortinet All Blogs
云风的 BLOG
云风的 BLOG
C
CERT Recently Published Vulnerability Notes
Project Zero
Project Zero
P
Proofpoint News Feed
B
Blog
Microsoft Security Blog
Microsoft Security Blog
L
LangChain Blog
G
GRAHAM CLULEY
S
Securelist
K
Kaspersky official blog
Spread Privacy
Spread Privacy
Stack Overflow Blog
Stack Overflow Blog
Security Latest
Security Latest
aimingoo的专栏
aimingoo的专栏
Cisco Talos Blog
Cisco Talos Blog
T
Tor Project blog
I
Intezer
NISL@THU
NISL@THU
The Register - Security
The Register - Security
P
Privacy International News Feed
Recent Announcements
Recent Announcements
MyScale Blog
MyScale Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
T
Tenable Blog
AI
AI
V2EX - 技术
V2EX - 技术
量子位
Jina AI
Jina AI
博客园 - Franky
N
News | PayPal Newsroom
Cloudbric
Cloudbric
N
News and Events Feed by Topic
J
Java Code Geeks

mafeifan 的编程技术分享

mafengwo-mp3-downloader | mafeifan 的编程技术分享 示例页面 | mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 查看 default namespace 下的 default service account名称 mafeifan 的编程技术分享 检查日志 | mafeifan 的编程技术分享 bridge fdb show dev flannel.1 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 数据收集原理分析 | mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 几种方法 | mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 check the export on the very top of this document so we can use $do mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 mafeifan 的编程技术分享 延伸 -- 关于前端路由 xdebug 3 和 2 的区别
mafeifan 的编程技术分享
2026-01-16 · via mafeifan 的编程技术分享

记录请求参数和请求内容 ​

默认morgan没有提供记录请求参数和请求内容的方法, 但是他提供了扩展方法,如下:

morgan.token('requestParameters', function(req, res){
  return JSON.stringify(req.query) || '-';
});

morgan.token('requestBody', function(req, res){
  return JSON.stringify(req.body) || '-';
});

// create custom format,includes the custom token
morgan.format('live-api', ':method :url :status :requestParameters :requestBody');

app.use(morgan('live-api'));

输出日志到数据库或将日志作为参数发送到其他请求 ​

默认日志信息是输出到命令行窗口中,能否输出到文件或数据库中呢?答案是肯定的 定义morgan的options中有个stream配置项,我们可以利用他做文章。

const request = require('request')
const split = require('split')

// 将日志信息作为请求参数传给其他地址,比如 Elasticsearch 日志分析系统
let httpLogStream = split().on('data', function (line) {
  request({
    url: 'localhost://192.168.1.1:8080',
    method: 'POST',
    body: line
  })
  .on('response', function(response) {
    console.log(response.statusCode) // 200
  })
});

app.use(morgan('common', {
  stream: httpLogStream
}));


// 将日志写入数据库
// 带write方法的对象
let dbStream = {
  write: function(line){
    saveToDatabase(line);  // 伪代码,保存到数据库
  }
};

// 将 dbStream 作为 stream 配置项的值
app.use(morgan('short', {stream: dbStream}));