@dazn/lambda-powertools-logger

中文文档
1.28.1发布于 2020/12/10MITTypeScriptCommonJS近 30 天下载 5.6万

与Lambda-power Tools紧密结合的Logger

中文使用文档

羊肉- 功用工具- 拖拉机

与其余部分紧密结合的伐木者 lambda-powertools,并知道自动包括任何与之相关的ID @dazn/lambda-powertools-correlation-ids。 。 。 .

主要特点:

  • 与 JSON 进行结构化记录

  • 包括若干共同属性: awsRegion, (中文(简体) ), functionName, (中文(简体) ), functionVersion, (中文(简体) ), functionMemorySize 财务报告和审定财务报表 environment

  • 支持以 enableDebug 函数(详见下文)

  • 允许通过 LOG_LEVEL 环境变量(允许值为 DEBUG, (中文(简体) ), INFO, (中文(简体) ), WARN 财务报告和审定财务报表 ERROR(中文(简体) )

  • 页:1 WARN 财务报告和审定财务报表 ERROR 日志,包括 errorName, (中文(简体) ), errorMessage 财务报告和审定财务报表 stackTrace

开始

从国家预防机制安装: npm install @dazn/lambda-powertools-logger

API 密码

这说明记录的API:

const Log = require('@dazn/lambda-powertools-logger')

Log.debug('this is a debug message')
Log.debug('this is a debug message with attributes', { userId: 'theburningmonk' })

Log.info('this is an info message')
Log.info('this is an info message with attributes', { userId: 'theburningmonk' })

Log.warn('this is a warning message')
Log.warn('this is a warning message with attributes', { userId: 'theburningmonk' })
Log.warn('this is a warning message', new Error('oops'))
Log.warn('this is a warning message with attributes, and error details', { userId: 'theburningmonk' }, new Error('oops'))

Log.error('this is an error message')
Log.error('this is an error message with attributes', { userId: 'theburningmonk' })
Log.error('this is an error message', new Error('oops'))
Log.error('this is an error message with attributes, and error details', { userId: 'theburningmonk' }, new Error('oops'))

我们不想在生产中留下调试记录,因为有重大影响:

  • 云表记录成本:云表记录每克摄入数据收费0.5美元

  • Logz.io 成本: Logz.io 也根据所摄入的数据收取费用

  • Lambda成本:从Cloud Watch Logs到Logz.io的日志也有Lambda引用成本

  • Lambda 货币:更多被记录的东西 = 更多 Lambda 引用将其运到 Logz.io , 可能用上太多的地区配额

  • 木头里太多的噪音 更难找到重要信息

相反,我们应该抽样调试日志 1%的引用.

当用其他羊肉达能工具时,例如. @dazn/lambda-powertools-middleware-sample-logging在引用时可以启用调试日志 enableDebug 函数.

这个 @dazn/lambda-powertools-middleware-correlation-ids 中间软件还可以通过允许您传播决定来补充此行为,从而能够将样本记录作为特殊的关联ID. 这允许整个呼叫链( 如 API Gateway - > Lambda - >) Kinesis - > Lambda - > SNS - > Lambda - > HTTP - > API Gateway - > Lambda),以尊重取样决定.

const Log = require('@dazn/lambda-powertools-logger')
// LOG_LEVEL is set to WARN via serverless.yml

Log.debug('this is not logged')

const undoDebugLog = Log.enableDebug()

Log.debug('this is logged')

undoDebugLog()

Log.debug('this is not logged')

版本与发布记录

@dazn/lambda-powertools-logger 共发布 11 个版本,首次发布于 2019/07/24;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.28.1latest2020/12/105 年前
1.28.02020/12/105 年前
1.24.12020/06/036 年前
1.24.02020/05/306 年前
1.23.12020/04/206 年前
1.23.02020/04/076 年前

关于 @dazn/lambda-powertools-logger 的常见问题

@dazn/lambda-powertools-logger 是什么?

与Lambda-power Tools紧密结合的Logger

如何安装 @dazn/lambda-powertools-logger?

在项目目录运行 npm install @dazn/lambda-powertools-logger,或使用 pnpm add / yarn add / bun add。

@dazn/lambda-powertools-logger 支持 TypeScript 吗?

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

@dazn/lambda-powertools-logger 支持 ESM 还是 CommonJS?

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

@dazn/lambda-powertools-logger 可以商用吗?

@dazn/lambda-powertools-logger 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@dazn/lambda-powertools-logger 的下载量有多少?

根据 npm 官方下载统计,@dazn/lambda-powertools-logger 在 2026/10/12 – 2026/11/10 这 30 天内被下载 55,857 次,日均约 1,862 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@dazn/lambda-powertools-logger 还在维护吗?

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