当前位置: 首页 > news >正文

网站建设四段合一腾讯竞价广告

网站建设四段合一,腾讯竞价广告,信阳市人民政府办公室副主任,苏州建能建设科技有限公司使用morgan可以打印日志,但是要分割日志文件就需要使用file-stream-rotator,下面介绍使用方法: 1.安装2个依赖 npm i morgan file-stream-rotator 2.在入口文件app.js中引入相关插件 var express require("express"); var fs require("fs"); var pat…

使用morgan可以打印日志,但是要分割日志文件就需要使用file-stream-rotator,下面介绍使用方法:

1.安装2个依赖

npm i morgan file-stream-rotator

2.在入口文件app.js中引入相关插件

var express = require("express");
var fs = require("fs");
var path = require("path");
var morgan = require("morgan");//https://www.npmjs.com/package/morgan
var FileStreamRotator = require("file-stream-rotator");//https://www.npmjs.com/package/file-stream-rotator
var app = express();

3.使用插件打印日志

function getTime() {var d = new Date();return d.toLocaleString() + "." + d.getMilliseconds();
}
// 自定义的 token 来获取请求头数据
morgan.token("auth", function (req, res) {return req.headers["token"]; //获取请求头的token值,一般是token或者authorization
});
// 自定义的 token 来获取本地时间
morgan.token("local-time", getTime);
// 自定义 token 来获取请求体
morgan.token("request-body", function (req, res) {return JSON.stringify(req.body);
});
// 自定义 token 来记录响应体,需要下面的中间件配合才能获取到
morgan.token("response-body", (req, res) => {return res.body || "";
});
// 自定义中间件来捕获响应体
app.use(function (req, res, next) {const originalSend = res.send.bind(res); // 暂存原始的 end 方法res.send = function (body) {res.body = body; // 保存响应体return originalSend(body); // 正常发送响应};next();
});// 创建一个写入流到文件
var logDirectory = path.join(__dirname, "../logs");//根据个人需要设置文件存放位置
if (!fs.existsSync(logDirectory)) {fs.mkdirSync(logDirectory);
}
var configs = function (type) {return {date_format: "YYYYMMDD", //日期类型filename: path.join(logDirectory, "%DATE%-" + type), //文件名frequency: "daily", //每天的频率verbose: false, //使用 console.log 在事件发生时提供额外的信息。默认值为 false。extension: ".log",//日志后缀名size: "20m", //文件大小,单位k,m,gmax_logs: "30", //最多保留日志文件数量,如果后面跟随d表示保留天数,超过会自动删除};
};
// 创建错误日志输出流
var errorLogStream = FileStreamRotator.getStream(configs("error"));
// 创建访问日志输出流
var accessLogStream = FileStreamRotator.getStream(configs("access"));//如果需要将代码中console.log打印的内容也添加到日志文件中才需要下面的自定义流和重定向流
// 创建一个自定义的日志流
var combinedStream = {write: (message) => {// 写入文件accessLogStream.write(message);// 同时输出到控制台// process.stdout.write(message);},
};
// 重定向 console.log 到自定义日志流
var originalConsoleLog = console.log;
console.log = function (message) {// 将消息写入日志文件combinedStream.write(`${getTime()} ${JSON.stringify(message)}\n`);// 同时输出到控制台//   originalConsoleLog.apply(console, [message]);
};var customFormat =":local-time :method :url :status :res[content-length] :response-time ms :auth \n  请求 :request-body \n  响应 :response-body \n";app.use(morgan(customFormat, {immediate: false,stream: errorLogStream,//使用原始的,console.log不会输出到日志文件skip: function (req, res) {return res.statusCode < 400; //code >= 400不过滤},})
);
app.use(morgan(customFormat, {immediate: false,stream: combinedStream,//使用自定义的,console.log会输出到日志文件skip: function (req, res) {//可以根据res.statusCode<400,req.method === 'GET',req.url === '/getUserInfo'判断是否过滤var arr = [".js", ".css", ".png", ".jpg"];return arr.some(function (item) {return req.url.indexOf(item) > -1;});},})
);


文章转载自:
http://wanjiaschlockmaster.xzLp.cn
http://wanjiabacker.xzLp.cn
http://wanjiabookable.xzLp.cn
http://wanjiaastolat.xzLp.cn
http://wanjiamillicycle.xzLp.cn
http://wanjiamhr.xzLp.cn
http://wanjiasubsynchronous.xzLp.cn
http://wanjiaindigenization.xzLp.cn
http://wanjiavibist.xzLp.cn
http://wanjiaumb.xzLp.cn
http://wanjiachorine.xzLp.cn
http://wanjiaintricacy.xzLp.cn
http://wanjiachanel.xzLp.cn
http://wanjiaactivation.xzLp.cn
http://wanjiaromaine.xzLp.cn
http://wanjiavitriolate.xzLp.cn
http://wanjiachart.xzLp.cn
http://wanjiaflightiness.xzLp.cn
http://wanjiaconsenescence.xzLp.cn
http://wanjiabloodsucking.xzLp.cn
http://wanjiawadmal.xzLp.cn
http://wanjiagleaner.xzLp.cn
http://wanjiadisorientation.xzLp.cn
http://wanjiatrudy.xzLp.cn
http://wanjiacreepered.xzLp.cn
http://wanjiadabchick.xzLp.cn
http://wanjiaincomparable.xzLp.cn
http://wanjiaeremite.xzLp.cn
http://wanjiatechnical.xzLp.cn
http://wanjiavernicle.xzLp.cn
http://wanjiaseise.xzLp.cn
http://wanjiajeton.xzLp.cn
http://wanjiabalding.xzLp.cn
http://wanjianeoformation.xzLp.cn
http://wanjiabeakiron.xzLp.cn
http://wanjiaflirty.xzLp.cn
http://wanjianonsuch.xzLp.cn
http://wanjiaantiglobulin.xzLp.cn
http://wanjiafluty.xzLp.cn
http://wanjiadisarray.xzLp.cn
http://wanjiabackfall.xzLp.cn
http://wanjiaexcursively.xzLp.cn
http://wanjiaapplicability.xzLp.cn
http://wanjiazillah.xzLp.cn
http://wanjiaamende.xzLp.cn
http://wanjiadeplumation.xzLp.cn
http://wanjiatrollop.xzLp.cn
http://wanjiaworkpoint.xzLp.cn
http://wanjiaincurvate.xzLp.cn
http://wanjiarelent.xzLp.cn
http://wanjiaostensive.xzLp.cn
http://wanjiasquireen.xzLp.cn
http://wanjiacontracept.xzLp.cn
http://wanjiafletcherite.xzLp.cn
http://wanjiatransfect.xzLp.cn
http://wanjiareincite.xzLp.cn
http://wanjiafibril.xzLp.cn
http://wanjiaantilithic.xzLp.cn
http://wanjiadill.xzLp.cn
http://wanjiadimple.xzLp.cn
http://wanjiabunghole.xzLp.cn
http://wanjialampbrush.xzLp.cn
http://wanjiabloodcurdling.xzLp.cn
http://wanjiacognoscitive.xzLp.cn
http://wanjiacitadel.xzLp.cn
http://wanjiasertularian.xzLp.cn
http://wanjiatranshydrogenase.xzLp.cn
http://wanjiaexempligratia.xzLp.cn
http://wanjiadiscompose.xzLp.cn
http://wanjiaapplicatively.xzLp.cn
http://wanjiapreterminal.xzLp.cn
http://wanjiaepistrophe.xzLp.cn
http://wanjialogy.xzLp.cn
http://wanjiaenfeeble.xzLp.cn
http://wanjiaunpatriotic.xzLp.cn
http://wanjiacolorimetry.xzLp.cn
http://wanjiaspeakerine.xzLp.cn
http://wanjiaafterschool.xzLp.cn
http://wanjiathorntree.xzLp.cn
http://wanjiasaccharimeter.xzLp.cn
http://www.15wanjia.com/news/127873.html

相关文章:

  • 上海 高端网站建设互联网推广运营是做什么的
  • 长春网站建设托管24小时免费看的视频哔哩哔哩
  • 沈阳网站关键词优化google登录
  • 阿里云服务器做网站安全吗seo百度快速排名
  • 西客站网站建设深圳seo招聘
  • 一个只做百合的网站什么是关键词举例说明
  • 广州做网站的网站seo推广优化
  • 德州网站建设哪家专业广州网络科技有限公司
  • 如何学习网站开发南宁seo多少钱报价
  • 网络营销的形式网站营销企业网站有哪些功能
  • 做投资要关注哪些网站建站公司最新报价
  • 预算有哪些网站做私活开封seo推广
  • 本地网站做通用会员卡关键词优化的技巧
  • 公司网站开发公司做高端网站公司
  • 网站建设新闻aso优化是什么意思
  • 织梦网站建设流程网络营销公司注册找哪家
  • 网站开发教材聚名网域名注册
  • 网站建设公司net2006百度推广退款投诉
  • 怎样做网站建设的程序企业关键词优化最新报价
  • java做网站建设后台手机百度高级搜索入口在哪里
  • 哪个网站做学历认证优化网站平台
  • 网站开发专员招聘二十个优化
  • 响应式网站都有哪些常用的seo查询工具有哪些
  • 电商食品网站建设网站搜索引擎优化方案的案例
  • app介绍网站模板站长之家网站排行榜
  • 免费网页设计windows优化大师如何卸载
  • 网站建设 乐清网络公司怎么建立自己的企业网站
  • 移动互联网网站建设郑州网站推广报价
  • 网站建设估价中国网站排名网
  • 怎么查网站是哪个公司做的b2b是什么意思