当前位置:网站首页>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 压缩备份文件
}
}
边栏推荐
- jmeter接口压力测试-(二)
- Paper reading: SegFormer: Simple and Efficient Design for Semantic Segmentation with Transformers
- Meikle Studio-Look at Hongmeng Device Development Practical Notes 7-Network Application Development
- 梅科尔工作室-看鸿蒙设备开发实战笔记六—无线联网开发
- 软考 系统架构设计师 简明教程 | 案例分析 | 需求分析
- Scrapy爬虫之网站图片爬取
- Container Technology - A Simple Understanding of Kubernetes Objects
- 4. yolov5-6.0 ERROR: AttributeError: 'Upsample' object has no attribute 'recompute_scale_factor' solution
- Re17: Read the paper Challenges for Information Extraction from Dialogue in Criminal Law
- 【HMS core】【FAQ】HMS Toolkit典型问题合集1
猜你喜欢

WARN: Establishing SSL connection without server's identity verification is not recommended when connecting to mysql

PyQt5 - draw text on window

Re15:读论文 LEVEN: A Large-Scale Chinese Legal Event Detection Dataset

Re21: Read the paper MSJudge Legal Judgment Prediction with Multi-Stage Case Representation Learning in the Real

Re17: Read the paper Challenges for Information Extraction from Dialogue in Criminal Law
![[Deep Learning] (Problem Record) <What do I get by calculating the gradient of a variable> - Linear Regression - Small Batch Stochastic Gradient Descent](/img/28/834aac16859fd26ab69de30f5fed55.png)
[Deep Learning] (Problem Record)
- Linear Regression - Small Batch Stochastic Gradient Descent 
jmeter接口压力测试-(二)

spark udf 接受并处理 null值.

Practical Walkthrough | Calculate Daily Average Date or Time Interval in MySQL

Linux内核设计与实现(十)| 页高速缓存和页回写
随机推荐
Drag and drop events, dataTransfer, getBoundingClientRect
Easy gene: human tRNA gene loci showed age-related high DNA methylation | research articles
spark udf accepts and handles null values.
Neural Network Study Notes 3 - LSTM Long Short-Term Memory Network
SST-Calib: A lidar-visual extrinsic parameter calibration method combining semantics and VO for spatiotemporal synchronization calibration (ITSC 2022)
Soft Exam System Architect Concise Tutorial | Case Analysis | Requirement Analysis
Database dirty reads, non-repeatable reads, phantom reads and corresponding isolation levels
[Deep Learning] (Problem Record)
- Linear Regression - Small Batch Stochastic Gradient Descent 第1章 Kali与靶机系统
Online target drone prompt.ml
Day113. Shangyitong: WeChat login QR code, login callback interface
【AGC】增长服务2-应用内消息示例
Adaptive Control - Simulation Experiment 1 Designing Adaptive Laws Using Lyapunov's Stability Theory
STM32CubeMX configuration to generate FreeRTOS project
nacos实战项目中的配置
类和对象—6个默认成员函数
易基因:人类tRNA基因位点表现出与衰老相关的DNA高甲基化|研究文章
idea2021+Activiti [the most complete note one (basic use)]
你真的懂Redis的5种基本数据结构吗?
spark udf 接受并处理 null值.