@solutions-builder/solutions-logger v1.0.1
@aws-solutions client-library
Client library for following use cases: //@aws-solutions
- logging
- error notification
The library is forked and developed from winston
Pre-Requisites
Winston 3+
Installation
npm install —save git+ssh://codecommit-sb-repo/v1/repos/clientLibrary#v1.0.2 #TODO
Logging Levels
Logging levels in winston conform to the severity ordering specified by RFC5424: severity of all levels is assumed to be numerically ascending from most important to least important.
Each level is given a specific integer priority. The higher the priority the more important the message is considered to be, and the lower the corresponding integer priority. For example, as specified exactly in RFC5424 the syslog levels are prioritized from 0 to 7 (highest to lowest).
{
emerg: 0,
alert: 1,
crit: 2,
error: 3,
warning: 4,
notice: 5,
info: 6,
debug: 7
}
Usage in microservice (Lambda)
'use strict'
const Logger = require('./winston-wrapper')
exports.handler = async (event, context) => {
const data = {
a: 1,
b: 2,
c: 'str',
securedNumber: 1234565789
}
Logger.info(data, {
label: 'gs-ms'
})
return 'done'
}
Set up for error notifications
The module supports error notification through SNS and Slack both of which are as per customer needs and customized through environment variables
//slack transport channel
...(
process.env.SLACK_ERROR_NOTIFICATION == 'true' ? [new SlackHook({
webhookUrl: process.env.SLACK_HOOK,
channel: process.env.SLACK_CHANNEL,
level: 'error',
formatter: info => {
return {
text: `[${info.level.toUpperCase()}] ${(info.label)?`[${info.label}]`:''} ${info.timestamp}: ${JSON.stringify(info.message, null, 2)}`,
}
}
})] : []),
//sns transport channel
...(
process.env.SNS_ERROR_NOTIFICATION == 'true' ? [new WinstonSNS({
topic_arn: process.env.SNS_TOPIC_ARN,
level: 'error'
})] : []),
Message formatting and paramters TODO
License
Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.