@3fv/logger 中文文档教程
# @3fv/logger
Overview
@3fv/logger
源自 typelogger
,灵感来自 slf4j
, log4j2
& logback
等,
Install
非常简单
yarn add @3fv/logger
Setup
,再简单不过了
import * as Path from "path"
import {getLogger, configure, Level} from "@3fv/logger"
import { ConsoleAppender } from "@3fv/logger/appenders/console/ConsoleAppender"
import { FileAppender } from "@3fv/logger/appenders/files/FileAppender"
import { RollingFileAppender } from "@3fv/logger/appenders/files/RollingFileAppender"
// Chained configure() function supports every option
configure()
.appenders([
new ConsoleAppender(),
new FileAppender("file", {
filename: (index: number = -1) => Path.join("/tmp", index > -1 ?
`spec.file.appender.${index}.log` :
"spec.file.appender.log")
}),
new RollingFileAppender("rolling-file", {
filename: (index: number = -1) => Path.join("/tmp", index > -1 ?
`spec.rolling.file.appender.${index}.log` :
"spec.rolling.file.appender.log"),
maxFiles: 3,
maxSize: 1
})
])
.threshold(Level.trace)
const log = getLogger(__filename)
log.info('What up!!!')
# @3fv/logger
Overview
@3fv/logger
born from typelogger
inspired by slf4j
, log4j2
& logback
, etc.
Install
Pretty simple
yarn add @3fv/logger
Setup
It couldn't be much easier
import * as Path from "path"
import {getLogger, configure, Level} from "@3fv/logger"
import { ConsoleAppender } from "@3fv/logger/appenders/console/ConsoleAppender"
import { FileAppender } from "@3fv/logger/appenders/files/FileAppender"
import { RollingFileAppender } from "@3fv/logger/appenders/files/RollingFileAppender"
// Chained configure() function supports every option
configure()
.appenders([
new ConsoleAppender(),
new FileAppender("file", {
filename: (index: number = -1) => Path.join("/tmp", index > -1 ?
`spec.file.appender.${index}.log` :
"spec.file.appender.log")
}),
new RollingFileAppender("rolling-file", {
filename: (index: number = -1) => Path.join("/tmp", index > -1 ?
`spec.rolling.file.appender.${index}.log` :
"spec.rolling.file.appender.log"),
maxFiles: 3,
maxSize: 1
})
])
.threshold(Level.trace)
const log = getLogger(__filename)
log.info('What up!!!')