当前位置:网站首页>log4js入门
log4js入门
2022-07-30 10:14:00 【地图学】
log4js是一个nodejs日志管理库,简单易用。
一、安装
npm install log4js --save
二、最简单的使用
const log4js = require('log4js');
const logger=log4js.getLogger();
logger.level='trace';//必须设置
logger.error('err');
结果如下:
三、配置
Appender 必须配合categories使用否则报错
1.appenders 输出
{
appenders:{
default:{
type:‘file’,
filename:‘default.log’
}
}
2.Categories
{
categories:{
default:{
appenders:[“default”],
level:“error”
}
}
使用实例
const log4js = require('log4js');
const logger=log4js.getLogger();
log4js.configure(
{
appenders:{
default:{
type:'file',
filename:'default.log'
}
},
categories:{
default:{
appenders:["default"],
level:"error"
}
}
});
//logger.level='trace';//必须设置
logger.debug("debug");
logger.error('err');
结果如下:
特别记录appender为file时的属性配置
appenders:{
default:{
type:'file',
filename:'default.log',
maxLogSize:1,//日志文件的最大大小
backups: 2,//在日志滚动期间要保留的旧日志文件的数量,不包括当前日志
compress: true//使用 gzip 压缩备份文件
}
}
边栏推荐
- GNOME 新功能:安全启动被禁用时警告用户
- 类和对象—6个默认成员函数
- Database dirty reads, non-repeatable reads, phantom reads and corresponding isolation levels
- Adaptive Control - Simulation Experiment 1 Designing Adaptive Laws Using Lyapunov's Stability Theory
- MySQL |子查询
- EViews 12.0 software installation package download and installation tutorial
- Soft Exam System Architect Concise Tutorial | Case Analysis | Requirement Analysis
- 【 HMS core 】 【 Analytics Kit] [FAQ] how to solve the payment amount in huawei pay analysis shows zero problem?
- Easy gene: human tRNA gene loci showed age-related high DNA methylation | research articles
- 神经网络学习笔记3——LSTM长短期记忆网络
猜你喜欢

idea2021+Activiti【最完整笔记一(基础使用)】

SST-Calib: A lidar-visual extrinsic parameter calibration method combining semantics and VO for spatiotemporal synchronization calibration (ITSC 2022)

JCL 学习

Re19: Read the paper Paragraph-level Rationale Extraction through Regularization: A case study on European Court

你真的懂Redis的5种基本数据结构吗?

【HMS core】【Analytics Kit】【FAQ】如何解决华为分析付费分析中付款金额显示为0的问题?

张量篇-初步

线程池方式开启线程--submit()和execute()的区别

ospf2 two-point two-way republish (question 2)

第2章 常用安全工具
随机推荐
阿里云OSS对象存储
分页 paging
RandLA-Net复现记录
Container Technology - A Simple Understanding of Kubernetes Objects
MFCC to audio, the effect should not be too funny >V
jmeter接口压力测试-(二)
ospf2 two-point two-way republish (question 2)
【HMS core】【FAQ】HMS Toolkit典型问题合集1
Re16:读论文 ILDC for CJPE: Indian Legal Documents Corpus for Court Judgment Prediction and Explanation
Flask之路由(app.route)详解
Always remember: one day you will emerge from the chrysalis
再有人问你分布式事务,把这篇扔给他
Neural Network Study Notes 4 - Autoencoder (including sparse, stacked) (updated)
图像去噪——Neighbor2Neighbor: Self-Supervised Denoising from Single Noisy Images
拖放事件,dataTransfer,getBoundingClientRect
OC-手动引用计数内存管理
[HarmonyOS] [ARK UI] How to double-click the return key to exit in HarmonyOS ets language
Materialist Dialectics - Conditionalism
By building a sequence table - teach you to calculate time complexity and space complexity (including recursion)
If someone asks you about distributed transactions again, throw this to him