Skip to content

trojs/logger

Folders and files

NameName
Last commit message
Last commit date
Jul 4, 2024
Dec 18, 2023
Aug 26, 2024
Oct 16, 2023
Jul 25, 2024
Oct 16, 2023
Oct 16, 2023
Aug 21, 2024
Oct 16, 2023
Oct 16, 2023
Oct 16, 2023
Nov 29, 2023
May 21, 2024
May 21, 2024
Aug 26, 2024
Nov 29, 2023
Dec 18, 2023
Aug 26, 2024
Aug 26, 2024
Jun 29, 2024
Oct 16, 2023

Repository files navigation

logger

Generic logger with intergrations for e.g. Sentry

import makeLogger from '@trojs/logger';

const logger = makeLogger({
  level: 'info', 
  service: 'user-service',
  loggers: [
    {
      type: 'console'
    },
    {
      type: 'sentry',
      level: 'error',
      location: 'https://[email protected]/1234567'
    }
  ]
})

try {
  throw new Error('example')
} catch(error) {
  logger.error(error, { whatever: "is sent as extra" });
}

level

default: info

Log only if info.level less than or equal to this level

More info see: https://www.npmjs.com/package/winston#logging-levels

service

default: user-service

Loggers:

Set of logging targets for info messages

default:

[
  {
    type: 'console'
  }
]

Types:

  • sentry
  • errorFile
  • combinedFile
  • console

The default loggers are overruled by the loggers in the loggers array.

It use winston transports for all logger types. More info see: https://www.npmjs.com/package/winston#transports

sentry

  • location (sentry.dsn)
  • environment (default: production, sentry.environment)
  • serverName (default: localhost, sentry.serverName)
  • release (default: unknown, sentry.release)
  • debug (default: false, sentry.debug)
  • sampleRate (default: 1, sentry.sampleRate)
  • tracesSampleRate (default: 1, senty.tracesSampleRate)
  • level (default: info)

DSN:

The DSN tells the SDK where to send the events. If this value is not provided, the SDK will try to read it from the SENTRY_DSN environment variable. If that variable also does not exist, the SDK will just not send any events.

More info:

errorFile

  • location (default: error.log)
  • level (default: error)

combinedFile

  • location (default: combined.log)

console

  • level (default: trace)
  • debug (default: false, stacktrace in console)
  • format (default: simple, also possible to set to json which is useful for different log systems)