@adobe/aio-lib-core-logging

中文文档
3.0.2发布于 2024/11/14Apache-2.0TypeScriptCommonJS近 30 天下载 11.9万

Logger framework for the Adobe I/O SDK

原始使用文档
文档目录13 节
  1. Install
  2. Use
  3. Output
  4. Configuration
  5. Enabling Debug Level Logging on command line
  6. Enabling Debug Level Logging programatically
  7. Using custom logger
  8. Send logs to a file
  9. Custom winston transports
  10. Creating custom logger
  11. Explore
  12. Contributing
  13. Licensing

aio-lib-core-logging

Version Downloads/week Node.js CI License Codecov Coverage

Node.js Logger module for use by the Adobe I/O SDK

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 global log level can also be overridden using the env variable AIO_LOG_LEVEL or the env variable LOG_LEVEL.

Enabling Debug Level Logging on command line

Avoid setting the global env variable by passing the log configuration in front of the aio command and stax flexibel.

To see all logs, do

$ DEBUG=* aio app run

Once you have figured out what logs you are interrested in, use something more specific, like

$ DEBUG=aio-telemetry:telemetry-lib* aio config

Enabling Debug Level Logging programatically

Example of logger configuration:

const logger = require('@adobe/aio-lib-core-logging')('MyModuleName', {provider: 'debug'})
logger.info('info')
logger.debug('debug')

To see both logs:

AIO_LOG_LEVEL = debug
DEBUG = MyModuleName

It is possible to set the log level from another environment variable if needed:

const logger = require('@adobe/aio-lib-core-logging')('MyModuleName', {provider: 'debug', level: process.env.FOOBAR})
logger.info('info')
logger.debug('debug')

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.

版本与发布记录

@adobe/aio-lib-core-logging 共发布 18 个版本,首次发布于 2019/09/24;过去 12 个月发布了 0 个版本。

版本发布日期距今
3.0.2latest2024/11/142 年前
3.0.12024/02/122 年前
3.0.02024/01/102 年前
2.0.1-pre.2024-01-08.sha-cbe78b13next2024/01/082 年前
2.0.1-pre.2023-07-10.sha-71ccb2c42023/07/103 年前
2.0.12023/07/063 年前

关于 @adobe/aio-lib-core-logging 的常见问题

@adobe/aio-lib-core-logging 是什么?

Logger framework for the Adobe I/O SDK

如何安装 @adobe/aio-lib-core-logging?

在项目目录运行 npm install @adobe/aio-lib-core-logging,或使用 pnpm add / yarn add / bun add。

@adobe/aio-lib-core-logging 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@adobe/aio-lib-core-logging 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@adobe/aio-lib-core-logging 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=18。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@adobe/aio-lib-core-logging 可以商用吗?

@adobe/aio-lib-core-logging 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@adobe/aio-lib-core-logging 的下载量有多少?

根据 npm 官方下载统计,@adobe/aio-lib-core-logging 在 2026/10/05 – 2026/11/03 这 30 天内被下载 119,127 次,日均约 3,971 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@adobe/aio-lib-core-logging 还在维护吗?

最新版本 3.0.2 发布于 2024/11/14(2 年前);至今共发布 18 个版本,其中过去 12 个月发布了 0 个;首次发布于 2019/09/24。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。