Giter Club home page Giter Club logo

aio-lib-core-logging's Introduction

aio-lib-core-logging

Version Downloads/week Build Status 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 log level can also be overridden using the env variable AIO_LOG_LEVEL

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.

aio-lib-core-logging's People

Contributors

amulyakashyap09 avatar arjuncooliitr avatar dependabot[bot] avatar filmaj avatar greenkeeper[bot] avatar himavanth avatar michaelgoberling avatar moritzraho avatar purplecabbage avatar rajarju avatar sandeep-paliwal avatar shazron avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

aio-lib-core-logging's Issues

Have an equivalent to console.time() and console.timeEnd() logging

Expected Behaviour

Have an equivalent to console.time() and console.timeEnd() logging, to provide rough timing of internal functions.

Actual Behaviour

logger.time() is not a function.

Reproduce Scenario (including but not limited to)

Inside an App Builder action, add a timing function.

Steps to Reproduce

Platform and Version

Sample Code that illustrates the problem

Logs taken while reproducing problem

An in-range update of codecov is breaking the build 🚨

The devDependency codecov was updated from 3.6.4 to 3.6.5.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

codecov is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details

Commits

The new version differs by 2 commits.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

logging should support string substitutions

for (let i=0; i<3; i++) {
    console.log("Hello, %s. You've called me %d times.", "Bob", i+1)
    aioLogger.debug("Hello, %s. You've called me %d times.", "Bob", i+1)
  }
2020-03-10T22:55:14.531Z       stdout: Hello, Bob. You've called me 1 times.
2020-03-10T22:55:14.532Z       stdout: 2020-03-10T22:55:14.532Z @adobe/aio-app-myapps/resolver:debug Hello, %s. You've called me %d times.
2020-03-10T22:55:14.532Z       stdout: Hello, Bob. You've called me 2 times.
2020-03-10T22:55:14.532Z       stdout: 2020-03-10T22:55:14.532Z @adobe/aio-app-myapps/resolver:debug Hello, %s. You've called me %d times.
2020-03-10T22:55:14.533Z       stdout: Hello, Bob. You've called me 3 times.
2020-03-10T22:55:14.533Z       stdout: 2020-03-10T22:55:14.533Z @adobe/aio-app-myapps/resolver:debug Hello, %s. You've called me %d times.

Add a console.table equivalent log formatter

Expected Behaviour

To help with debugging and building actions, a console.table() equivalent for logger would be preferential. This would allow for Arrays and Objects to be passed and output as a table in the various log locations.

Actual Behaviour

Currently not available (or not documented?), have to us logger.info/debug/etc and output a string.

Reproduce Scenario (including but not limited to)

N/A

Steps to Reproduce

N/A

Platform and Version

v2.0.0

Sample Code that illustrates the problem

N/A

Logs taken while reproducing problem

N/A

add ability to set log level after logger is constructed

Description

Right now you have to set the log level via the constructor like so:

const aioLogger = require('@adobe/aio-lib-core-logging')('App', { level: 'info' })

function main (params) {
     // you can't set the log level here, it is already fixed to `info` above
    // thus .debug won't output anything
     aioLogger.debug('this will not output anything')
}

Proposed setLogLevel feature

const aioLogger = require('@adobe/aio-lib-core-logging')('App')

function main (params) {
    // the log level is by default `info` and you can't change it after construction,
    // unless you add this feature like so
    aioLogger.setLogLevel(params.LOG_LEVEL)
   // if params.LOG_LEVEL was 'debug', now debug logs will show in the output
   aioLogger.debug('this will output if params.LOG_LEVEL is debug')
}

Workaround

The workaround is to create the logger with the log level, in your function scope.

const coreLogger = require('@adobe/aio-lib-core-logging')

function main (params) {
    const  aioLogger = coreLogger('App', { level: params.LOG_LEVEL })
   // if params.LOG_LEVEL was 'debug', debug logs will show in the output
    aioLogger.debug('this will output if params.LOG_LEVEL is debug')
}

An in-range update of eslint-plugin-jest is breaking the build 🚨

The devDependency eslint-plugin-jest was updated from 23.6.0 to 23.7.0.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

eslint-plugin-jest is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details

Release Notes for v23.7.0

23.7.0 (2020-02-07)

Bug Fixes

Features

  • valid-title: support disallowedWords option (#522) (38bbe93)
Commits

The new version differs by 7 commits.

  • 88068a7 chore(release): 23.7.0 [skip ci]
  • c12b725 fix(expect-expect): use u flag in regex (#532)
  • ff25588 chore(deps): removed dependency on micromatch for expect-expect (#517)
  • 38bbe93 feat(valid-title): support disallowedWords option (#522)
  • 1449675 chore: make gh actions badge always point to master
  • 95cce6b chore(deps): lock file maintenance (#490)
  • 735f143 chore(lint): enable require-unicode-regexp rule (#520)

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Replace winston/debug logger with Pino

Pino

Pino is a lightweight logging library which is ideal for serverless logging.
It is a good candidate to replace winston-logger and debug providers

  • Pino streams logs in NDJSON (Line delimited JSON) to standard output
  • Pino core does not include transports, does not support in process transport
  • Pino core does not include custom formating, only logs in JSON
  • Pino API is similar/compatible with winston

Additional features

Pino plugins

Aio Core Logger Features

  • multiple logger types
  • write to file
  • custom formats

Double timestamps in runtime action logging

In my runtime action code, I am doing this:

const aioLogger = require('@adobe/aio-lib-core-logging')('@adobe/aio-app-myapps/resolver', { provider: 'debug', level: 'debug' })
...
// and later
aioLogger.debug('resolver got a request')

When I look at the logs, I see this:

2020-03-10T22:35:04.802Z       stdout: 2020-03-10T22:35:04.802Z @adobe/aio-app-myapps/resolver:debug  resolver got a request

With the double time stamp, plus the stream name, plus a verbose debug namespace, there are 100 char before the message.

Debug label not intuitive, should be log prefix?

Expected Behaviour

test.js:

const logger = require('@adobe/aio-lib-core-logging')('myapp', { provider: './DebugLogger' })
logger.debug('yo!')

DEBUG=myapp node test.js => should print yo!

Actual Behaviour

Need to add a * to the DEBUG env var
DEBUG=myapp* node test.js => prints yo!

This is because the debug label is extended with action name and log level

suggestion: preserve the user given debug key but add a string prefix to each log message

[Draft] Proposal: remove debug logger as provider

Proposal to remove debug logger as the default log provider and use winston logger.

Core logger

  • Custom Formatter support
    • Logging in JSON
    • Eternal Log viewers
  • Customise transports
  • Log levels
  • Switch log levels with env variables

debug logger

  • Debug logger uses a global DEBUG env variable to define log level and it cannot be over ridden by the aio library.
  • The environment variable takes precedence over AIO_LOG_LEVEL
  • Logs from 3rd party dependencies will also be logged when using this env variable

Winston

  • Use winston as the only log provider
  • Expose more winston configs via the aio core logger
  • Dependency size

Other Loggers

Logger Package Size (Minified)
winston 136.9 kB
bunyan 15.7 kB
log4js 77.2 kB
pino 6.3 kB

Bunyan

  • API Similar to winston
  • Serializers can be complicated
  • Supports multiple streams
  • Child loggers

Pino

winston log provider: add ability to modify config for showing/hiding timestamp

If you choose the winston log provider, it adds a timestamp by default. Add an option in the config to not show the timestamp, and also the ability to turn on/off timestamp after initialization.

Proposed

// init winston logger (timestamp is true by default for backwards compat)
const aioLogger = require('@adobe/aio-lib-core-logging')('App', {provider:'winston', timestamp: false })
// turn on the timestamp later 
aioLogger.config.timestamp = true // use a setter

logging should pretty print objects

console.log(obj1 [, obj2, ..., objN])

console.log outputs a hson representation of each object passed to it.

console.log('resolver got request: ', request)
aioLogger.debug('resolver got request: ', request)
// console.log output:
2020-03-10T23:00:56.312Z       stdout: resolver got request:  { org: 'asdsomeorg@AdobeOrg',
  path: '/',
  clientId: 'aio-app-myapple',
  tenant: '3124',
  imsProfile: ...
  ...
}
// aioLogger.debug output:
2020-03-10T23:00:56.313Z       stdout: 2020-03-10T23:00:56.312Z @adobe/aio-app-myapps/resolver:debug resolver got request:

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.