@adobe/aio-lib-core-logging 中文文档教程

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

aio-lib-core-logging

版本 下载/周 构建状态 许可”></a>  
  <a href=Codecov Coverage

Install

npm install @adobe/aio-lib-core-logging

Use

let aioLogger = require('@adobe/aio-lib-core-logging')('App')
aioLogger.info('Hello logs')

Output

以上代码将记录以下

[App /mynamespace/myaction] 信息: Hello logs

其中 App 将是发送日志的应用程序/模块的名称。

Configuration

可以通过在创建时传递配置对象来自定义记录器。

let aioLogger = require('@adobe/aio-lib-core-logging')('App', config)

配置对象可以具有以下一个或多个键。

  • level (max severity logging level to be logged. can be one of error, warn, info, verbose, debug, silly)
  • provider (logging provider. default is winston.)
  • logSourceAction (boolean to control whether to include the action name in the log message)
  • transports (array of custom winston transports)

日志级别也可以使用 env 变量 AIOLOGLEVEL 覆盖,

Using custom logger

// Winston Logger
let aioLogger = require('@adobe/aio-lib-core-logging')('App', {provider:'winston'})
aioLogger.info('Hello logs')

或者

// Debug Logger
let aioLogger = require('@adobe/aio-lib-core-logging')('App', {provider:'debug'})

Send logs to a file

let aioLogger = require('@adobe/aio-lib-core-logging')('App', {transports: './logfile.txt' })

Custom winston transports

const winston = require('winston')
let aioLogger = require('@adobe/aio-lib-core-logging')('App', {transports: [new winston.transports.File({ filename: './winstoncustomfilelog.txt' })]})

Creating custom logger

这目前就像在 src 下创建一个新的记录器类一样简单,所有日志级别函数都已定义

Explore

goto API

Contributing

欢迎贡献! 阅读贡献指南了解更多信息。

Licensing

这个项目是根据 Apache V2 许可证获得许可的。 有关详细信息,请参阅许可证

aio-lib-core-logging

Version Downloads/week Build Status License Codecov Coverage

Install

npm install @adobe/aio-lib-core-logging

Use

let aioLogger = require('@adobe/aio-lib-core-logging')('App')
aioLogger.info('Hello logs')

Output

Above code will log the following

[App /mynamespace/myaction] info: Hello logs

Where App would be the name of the application/module that is sending the logs.

Configuration

The logger can be customized by passing a config object at the time of creation.

let aioLogger = require('@adobe/aio-lib-core-logging')('App', config)

The config object can have one or more of the following keys.

  • level (max severity logging level to be logged. can be one of error, warn, info, verbose, debug, silly)
  • provider (logging provider. default is winston.)
  • logSourceAction (boolean to control whether to include the action name in the log message)
  • transports (array of custom winston transports)

The log level can also be overridden using the env variable AIOLOGLEVEL

Using custom logger

// Winston Logger
let aioLogger = require('@adobe/aio-lib-core-logging')('App', {provider:'winston'})
aioLogger.info('Hello logs')

or

// Debug Logger
let aioLogger = require('@adobe/aio-lib-core-logging')('App', {provider:'debug'})

Send logs to a file

let aioLogger = require('@adobe/aio-lib-core-logging')('App', {transports: './logfile.txt' })

Custom winston transports

const winston = require('winston')
let aioLogger = require('@adobe/aio-lib-core-logging')('App', {transports: [new winston.transports.File({ filename: './winstoncustomfilelog.txt' })]})

Creating custom logger

This is currently as simple as creating a new logger class under src with all the log level functions defined

Explore

goto API

Contributing

Contributions are welcomed! Read the Contributing Guide for more information.

Licensing

This project is licensed under the Apache V2 License. See LICENSE for more information.

更多

友情链接

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文