羊肉- 功用工具- 拖拉机
与其余部分紧密结合的伐木者 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')