0.1.6 • Published 1 year ago

@open-xchange/logging v0.1.6

Weekly downloads
-
License
MIT
Repository
gitlab
Last release
1 year ago

Logging

Logging for node.js projects.

Adheres to the rules defined in https://confluence.open-xchange.com/pages/viewpage.action?spaceKey=EN&title=Logging

Works for cjs and esm.

In the current implementation it uses pino and pino-http.

How to use in ESM Projects

Create a file in your project e.g. logger.js

import { createLogger, createHttpLogger } from '@open-xchange/logging'
config()

export const httpLogger = createHttpLogger()
export const logger = createLogger()

How to use in CJS Projects

Create a file in your project e.g. logger.js

const { createLogger, createHttpLogger } = require('@open-xchange/logging')

module.exports = {
  httpLogger: createHttpLogger(),
  logger: createLogger()
}

If you use express you can add a request logger middleware.

app.use(httpLogger)

Pretty Printing - Programmatically

If NODE_ENV=development is set in your environment logs are automatically pretty-printed, which is particularly useful when debugging e.g. with Okteto.

Pretty Printing - CLI mode

CLI mode is useful in production environments. You may want to use this with kubectl logs -f.

node index.js | pino-pretty -t 'SYS:mm/dd HH:MM:ss.l' -x fatal:0,error:3,warn:4,info:6,debug:7,trace:8 -X fatal:red,error:red,warn:yellow,info:green,debug:blue,trace:gray

You could also create a .pino-prettyrc in your current directory.

{
  "translateTime": "SYS:mm/dd HH:MM:ss.l",
  "customLevels": "fatal:0,error:3,warn:4,info:6,debug:7,trace:8",
  "customColors": "fatal:red,error:red,warn:yellow,info:green,debug:blue,trace:gray"
}

which gives you a much shorter call:

node index.js | pino-pretty
0.1.6

1 year ago

0.1.4

1 year ago

0.1.5

1 year ago

0.1.0

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.3

2 years ago

0.0.10

2 years ago

0.0.11

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago