Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

winston-logsene

sematext2.1kApache 22.1.2

Winston transport layer for Logsene

Logsene, sematext, elasticsearch, ELK, logger, log management, logging saas, centralized logging, winston

readme

This is a transport module for the winston logger winstonjs/winston for logging with Sematext Cloud.

Winston-Logsene combines the flexibility of using the Winston logging framework with Sematext Cloud (think Hosted Elasticsearch + Kibana). Create your free account and access token here.

Usage

const Logsene = require('winston-logsene')
const { createLogger, format, config } = require('winston')

const logger = createLogger({
  levels: config.npm.levels,
  transports: [new Logsene({
    token: process.env.LOGS_TOKEN,
    level: 'debug',
    type: 'test_logs',
    url: 'https://logsene-receiver.sematext.com/_bulk'
  })]
})

Options

  • token - Create your free account and access token here.
  • type - Type of your logs - please note you can define Elasticsearch mapping templates in Sematext Cloud
  • url - Sematext Cloud receiver URL (or URL for Sematext Enterprise / On Premises), defaults to Sematext Cloud (US) receiver https://logsene-receiver.sematext.com/_bulk. To ship logs to Sematext Cloud (EU) in Europe use https://logsene-receiver.eu.sematext.com/_bulk
  • handleExceptions - boolean 'true' logs 'uncaught exceptions'
  • handleErrors - boolean 'true' logs 'unhandled errors'
  • exitOnError - if set to 'false' process will not exit after logging the 'uncaught exceptions'
  • source - name of the logging source, by default name of the main node.js module
  • setSource - "true" adds "source" to the log event (modifies the object!), default false
  • rewriter - similar to rewriters in winston, rewriter allows modifying of log meta but only for the logsene transport. This is a simple function which takes level, msg, meta as parameter and returns the new meta array
  • flushOnExit - Handling SIGTERM, SIGQT, SIGINT and 'beforeExit' to flush logs and terminate. Default value: true.

Examples

var Logsene = require('winston-logsene')
const { createLogger, format, config } = require('winston')

// example for custom rewriter, e.g. add myServerIp field to all logs
var myServerIp = '10.0.0.12'

var logger = createLogger({
  levels: config.npm.levels,
  transports: [new Logsene({
    // set log level, defaut is 'info'
    level: 'debug',
    // optional set a format function
    format: format.splat(),
    token: process.env.LOGS_TOKEN,
    rewriter: function (level, msg, meta) {
      meta.ip = myServerIp
      return meta
    }
  })]
})

logger.info('debug', 'Info Message')
// use dynamic list of placeholders and parameters for format.splat(), and any Object as Metadata
logger.info('Info message no. %d logged to %s', 1, 'Sematext Cloud', {meta: 'test-log', count: 1, tags: ['test', 'info', 'winston']})
// message placeholders work the same way as in util.format()
// utilize tags (in the metadata object) as filter to be used in Sematext Cloud user interface
logger.info('Info Message', {tags: ['info', 'test']})
logger.error('Error message no. %d logged to %s', 1, 'Sematext Cloud', {meta: 'test-error', count: 1, tags: ['test', 'error', 'winston']})
logger.warn('Warning message no. %d logged to %s', 1, 'Sematext Cloud', {meta: 'test-warning', count: 1, tags: ['test', 'warning', 'winston']})
logger.debug('Debug message no. %d logged to %s', 1, 'Sematext Cloud', {meta: 'test-debug', count: 1})

Schema / Mapping definition for Meta-Data

It is possible to log any JSON Object as meta data, but please note Sematext Cloud stores data in Elasticsearch and therefore you should define an index template, matching your data structure. More about Elasticsearch mapping and templates for Sematext Cloud: https://sematext.com/blog/custom-elasticsearch-index-templates-in-logsene/

In addition you should use different types for different meta data structures to avoid type conflicts in Elasticsearch. Include a type name in the meta-data like {type: 'logType1', ...} - this overwrites the "type" property, specified in the contstructor.

logger.add (logsene, {token: process.env.LOGSENE_TOKEN, type: 'my_logs'})
// numeric id, log type from constructor
logger.info('hello', {id: 1})
// The next line will cause a type conflict in Elasticsearch/Sematext Cloud, because id was a number before
logger.info('hello', {id: 'ID-1'})
// using a different type, OK no type conflict for the field 'id' in Elasticsearch//Sematext Cloud
// because we use a different type in the Elasticsearch//Sematext Cloud index
logger.info('hello', {type: 'my_type_with_string_ids',{id: 'ID-1'}})

Security

  • HTTPS is enabled by default
  • Environment variables for Proxy servers:
    • For HTTPS endpoints (default): HTTPS_PROXY / https_proxy
          export HTTPS_PROXY=https://my-ssl-proxy.example
          export HTTPS_PROXY=http://my-proxy.example
    • For HTTP endpoints (e.g. On-Premises): HTTP_PROXY / http_proxy
          export HTTP_PROXY=http://my-proxy.example
          export HTTP_PROXY=https://my-ssl-proxy.example

License

Apache 2, see LICENSE file

changelog

Changelog

All notable changes to this project will be documented in this file. Dates are displayed in UTC.

Generated by auto-changelog.

2.1.2

  • chore: remove vulnerabilities and unused libraries #48
  • Bump vm2 from 3.9.15 to 3.9.16 #46
  • Bump cacheable-request from 10.2.3 to 10.2.7 #44
  • Bump vm2 from 3.9.12 to 3.9.15 #45
  • Bump parse-path and release-it #39
  • Bump got and release-it #40
  • Bump shelljs from 0.8.4 to 0.8.5 #42
  • Bump json-schema and jsprim #41
  • Bump minimatch and mocha #38
  • Bump decode-uri-component from 0.2.0 to 0.2.2 #37
  • Bump qs from 6.5.2 to 6.5.3 #36
  • Bump ansi-regex from 3.0.0 to 3.0.1 #34
  • Bump async from 3.2.0 to 3.2.4 #33
  • Bump node-fetch from 2.6.1 to 2.6.7 #32
  • Bump minimist from 1.2.5 to 1.2.6 #31
  • Bump color-string from 1.5.4 to 1.6.0 #30
  • Bump path-parse from 1.0.6 to 1.0.7 #29
  • Bump glob-parent from 5.1.1 to 5.1.2 #28

2.1.1

10 May 2021

2.1.0

13 January 2021

  • Bump ini from 1.3.5 to 1.3.8 #24
  • Release 2.1.0 de68334
  • Merge pull request #25 from sematext/issue-21 35e302c
  • added safe flat 57efc0f

2.0.12

23 September 2020

  • Bump node-fetch from 2.6.0 to 2.6.1 #23
  • Updated deps 1105dd4
  • Release 2.0.12 6360f3f

2.0.11

6 August 2020

  • update logsene-js dep to latest d47102b
  • Release 2.0.11 3962313
  • fixed error handler to not crash server 9864ca8

2.0.10

21 July 2020

2.0.9

21 July 2020

2.0.8

30 April 2020

  • 🖊️🖊️ Fixed typos in flushing logs. #20
  • added release config 868d124
  • updated deps ab6549f
  • update exmaple ab8e2a5

2.0.7

12 June 2019

  • 🐛🐛 Fix flushOnExit default. #19
  • update dependencies 792bff9
  • Release 2.0.7 17747d4

2.0.6

8 January 2019

2.0.5

28 November 2018

2.0.4

28 November 2018

2.0.3

28 November 2018

2.0.2

17 October 2018

2.0.1

17 October 2018

  • update to Winston 3.1 #18
  • update to Winston 3 #1
  • Release 2.0.1 e2378bd
  • Update major version 6b9e792
  • remove bithound badge 3a02029

1.2.5

16 July 2018

  • Fix error if app has no entry script #13
  • Update travis for node v8,v9 a8e5de9
  • Release 1.2.5 e1e4f83

1.2.4

31 August 2017

1.2.3

31 August 2017

1.2.2

30 August 2017

1.2.1

25 September 2016

1.2.0

25 August 2016

  • fix #10, log uncaughtErrors and flush in exit handlers #10
  • Release 1.2.0 30fca08

1.1.11

29 July 2016

1.1.10

28 July 2016

1.1.9

28 July 2016

1.1.8

28 July 2016

  • Added custom rewriter for winston-logsene #6
  • Moving conditional into parentheses. #5
  • Update README.md #4
  • Initial commit 83f923f
  • initial e52bb2e
  • add .jshintrc a2bbe72