@3fv/logger 中文文档教程

发布于 4年前 浏览 28 项目主页 更新于 3年前

# @3fv/logger

Overview

@3fv/logger 源自 typelogger ,灵感来自 slf4jlog4j2 & 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!!!')
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文