Socket
Book a DemoInstallSign in
Socket

@intellihr/lambda-logger

Package Overview
Dependencies
Maintainers
3
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@intellihr/lambda-logger

A logger which complies with intelliHR logging standard

0.0.8
latest
Source
npmnpm
Version published
Weekly downloads
0
Maintainers
3
Weekly downloads
 
Created
Source

Lambda Logger

A logger which complies with our logging standard (see Logging Format)

Get Started

  • Install

    yarn add @intellihr/lambda-logger
    # or
    npm i @intellihr/lambda-logger
    
  • Usage

    import { logger } from '@intellihr/lambda-logger'
    

Environment Variables

Logger uses environment variables to set default values. These are optional.

Available variables:

NameDefaultAvailable ValuesDescription
LOGGING_LEVELnullemerg,alert,crit, err, warning, notice, info, debugIf set, log only if level less than or equal to this level (see: Logging Level)
LOGGINGconsoleconsole, fileThis is where the logger puts its output.
LOG_FILE_LOCATION./output/log.txtAny valid path in stringOnly used when LOGGING=file. The path where the output log is stored
SERVICEnullstringSet default value for service
STAGEnullstringSet default value for environment
HOSTnullstringSet default value for host
REGIONnullstringSet default value for region
IS_OFFLINEnullstringIf not set, it will output the log using stdout to avoid extra prefix in AWS Lambda

For serverless, you can set the environment variables in the serverless.yml

provider:
  environment:
    LOGGING_LEVEL: ${env:LOGGING_LEVEL, 'info'}
    LOGGING: ${env:LOGGING, 'console'}
    SERVICE: ${self:service}
    STAGE: ${self:custom.stage}
    REGION: ${self:custom.region}

Logging Level

const levelMap = {
  emerg: 0,
  alert: 1,
  crit: 2,
  err: 3,
  warning: 4,
  notice: 5,
  info: 6,
  debug: 7
}

Logger Options

These are accepted as part of our standard (see Logging Format)

const {
  level,
  service,
  environment,
  region,
  host,
  timestamp,
  user,
  path,
  tags,
  status,
  message,
  data,
  tenant
} = options

logger.log(options)
// or
logger(options).log()

Logger Methods

See Logger Options for all the accepted options

import { logger } from '@intellihr/lambda-logger'

logger.emergency('message', options)
logger.alert('message', options)
logger.critical('message', options)
logger.error('message', options)
logger.warning('message', options)
logger.notice('message', options)
logger.info('message', options)
logger.debug('message', options)
logger.log(options)

Usage

See Logger Options for all the accepted options

See Logger Methods for all the available methods

Simple:

import { logger } from '@intellihr/lambda-logger'

// The belows are printing the same log
// case 1
const myLogger = logger({ tags: ['test'] })
myLogger.info('This is info')

// case 2
logger.info('This is info', { tags: ['test'] })

// case 3
logger.log({ level: 'info', tags: ['test'], message: 'This is info'})

// case 4
const myLogger = logger({ tags: ['test'] })
myLogger.log({ level: 'info', message: 'This is info'})

Advanced:

import { logger } from '@intellihr/lambda-logger'

const testLog = logger({ tags: ['test'] })

const logInfo = testLog.info
const logError = testLog.error

// Both with tags: ['test']
logInfo('This is info')
logError('This is error')

Example to create your own logger:

import { logger } from '@intellihr/lambda-logger'

class MyLogger {
  constructor (options) {
    this._logger = logger({
      service: 'my-service',
      ...options
    })
  }

  info (options) {
    this._logger.info(options)
  }
}

// This will attach both service and tags
const myLogger = newLogger({ tags: ['oh-my'] })
myLogger.info('This is an info')

Local Development

Run inside docker

docker-compose run --rm code /bin/sh
# or without mounting node_module
docker-composer run --rm code-mac /bin/sh

Test

yarn test

Lint

yarn lint

FAQs

Package last updated on 31 Jul 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.