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

Package detail

logsene-js

sematext5.2kApache 2.01.1.77TypeScript support: included

JavaScript client for Sematext Logs

Logsene, Sematext, logging, centralized logging, log management, log, elastic stack, elasticsearch, ELK

readme

JavaScript client for Sematext Logs.

Installation

npm install logsene-js --save

Usage

var Logsene = require('logsene-js')
var logger =  new Logsene ('LOGS-APP-TOKEN')
logger.log ('info', 'text message', {tags: ['a','b'], customField: 'custom-field'})

Constructor Parameters

  • token - Logs App token. Sign up here.
  • type - Optional. Default type of your logs - please note you can define Elasticsearch mapping templates in Sematext Logs
  • url - Sematext Logs receiver URL (e.g. if you are shipping logs to Sematext Enterprise), defaults to 'https://logsene-receiver.sematext.com/_bulk'
  • storageDirectory - Directory where to buffer logs in the case of failure
  • options:
    • useIndexInBulkUrl - If set to 'false' /bulk will be used /indexName/bulk otherwise.
    • httpOptions - general HTTP/HTTPS options for the request, e.g. SSL key,cert,passphrase,ca,rejectUNauthorized etc.
    • silent - If set to true, logsene-js will not log debug and errors to stdout. Used for prod envs, but not mandatory. This is false by default.

Special fields for indexing

In general Elasticsearch > 2.3 (including Sematext Logs) does not allow fields with leading underscore or dots in field names. Logsene-js converts such fields names (e.g. removing leading underscores, and replaces dots to underscores). However, a few fields are interpreted for indexing before renaming the fields:

  • type - used as 'type' in the index operation (bulk indexing)
  • id - used as 'id' in the index operation (bulk indexing)

Environment variables

  • LOGS_TMP_DIR - Directory to store failed bulk requests, for later re-transmission. Failed requests are not stored, when LOGS_TMP_DIR is not set.
  • LOG_INTERVAL - Time to collect logs before a bulk request is done. Default 10000 ms
  • LOGS_BULK_SIZE - Maximum size of a bulk request. Default 1000.
  • LOGS_MAX_MESSAGE_FIELD_SIZE - maximum size of the 'message' field, default 240k
  • LOGS_RECEIVER_URL - URL for the Sematext Logs receiver. E.g. for Sematext Enterprise version. Defaults to Sematext Logs SaaS receiver https://logsene-receiver.sematext.com/_bulk
  • LOGSENE_TMP_DIR - Directory where to buffer logs if the Elasticsearch endpoint is unavailable. If this is not set, logsene-js will not buffer logs at all.
  • LOGS_BUFFER_ON_APP_LIMIT - default 'true'. HTTP bulk requests are retried until Sematext starts accepting logs again. Please increase your daily limit setting in Logs App settings if you see "403, App limit reached" errors. Setting the value to 'false' will disable disk buffering only for failed http requests '403, Forbidden / App limit reached'. We recommend to keep the default setting 'true' to avoid any loss of logs.
  • LOGS_REMOVE_FIELDS - a comma separated list of fields, which should not be logged. For nested objects use a dot notation e.g. 'reques.body,request.size'

Note: Previous versions of logsene-js used LOGSENE instead of LOGS prefix for the settings above. Logsene-js is backward compatible to previous environment variable names. However all variable names with the LOGSENE prefix are depracated and might be removed in future relases.

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

Other related modules

  • Please check winston-logsene a transport layer for the winston logging framework.
  • Please see bunyan-logsene a transport layer for the bunyan logging framework.

changelog

Changelog

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

Generated by auto-changelog.

1.1.77

  • Fix node fetch issue and vulnerabilities #55
  • Housekeeping #51
  • chore: remove unused libraries and code #50

1.1.76

20 April 2023

  • Sc 15901 remove vulnerabilities #49
  • Bump vm2 from 3.9.15 to 3.9.16 #47
  • Bump http-cache-semantics from 4.1.0 to 4.1.1 #43
  • Bump vm2 from 3.9.12 to 3.9.15 #45
  • Bump shelljs from 0.8.4 to 0.8.5 #41
  • Bump json-schema and jsprim #39
  • Bump decode-uri-component from 0.2.0 to 0.2.2 #35
  • Bump ansi-regex from 3.0.0 to 3.0.1 #36
  • Bump minimatch and mocha #37
  • Bump qs from 6.5.2 to 6.5.3 #34
  • Bump minimist from 1.2.5 to 1.2.6 #32
  • Bump node-fetch from 2.6.1 to 2.6.7 #31
  • Bump ajv from 6.12.2 to 6.12.6 #30
  • Bump path-parse from 1.0.6 to 1.0.7 #28
  • Bump glob-parent from 5.1.1 to 5.1.2 #27
  • chore: remove unused libraries and code b76d6a8
  • Release 1.1.76 4c9aa4c
  • Fixed user strict typo 1583aae

1.1.75

2 June 2021

  • Bump hosted-git-info from 2.8.8 to 2.8.9 #26
  • Bump y18n from 4.0.0 to 4.0.1 #25
  • Bump ini from 1.3.5 to 1.3.8 #21
  • updated deps 953154d
  • Release 1.1.75 0e87c99

1.1.74

8 October 2020

1.1.73

23 September 2020

  • Bump node-fetch from 2.6.0 to 2.6.1 #18
  • Release 1.1.73 922d98a

1.1.72

20 August 2020

  • edited test cases to use new error handling logic 376cde5
  • optimize memory limit test a1d7275
  • Release 1.1.72 62a2cd7

1.1.71

7 August 2020

1.1.70

6 August 2020

1.1.69

6 August 2020

1.1.68

28 March 2020

1.1.67

6 February 2020

  • LOGS_REMOVE_FIELDS accepts dots in field name fb89d59
  • Release 1.1.67 419ec76

1.1.66

30 January 2020

1.1.65

30 January 2020

  • reduce default diskBuffer retransmit interval from 60 to 5 seconds ccc88a6
  • Release 1.1.65 df258b7

1.1.64

30 July 2019

1.1.63

30 July 2019

1.1.62

18 July 2019

1.1.61

18 July 2019

  • change max. buffer size and update dependencies 79efa86
  • Release 1.1.61 4d2537d

1.1.60

15 May 2019

1.1.59

15 May 2019

  • change host field -> os.host object c212d23
  • remove node v4/v5 and add v10/v11 aa4930b
  • Release 1.1.59 e8ce6e4

1.1.58

1 March 2019

1.1.57

28 February 2019

  • Fix errors sent in the bulk API being ignored #11
  • Wording tweaks b210da8
  • Release 1.1.57 c42f5ff
  • update dependencies b4aacc4

1.1.56

28 November 2018

  • apply JS standard-format 2582eb3
  • support old and new env variable names / replacing LOGSENE prefix with LOGS_ 4c98ee8
  • update README 6b2351d

1.1.55

26 November 2018

  • support REMOVE_FIELDS in parallel to LOGSENE_REMOVE_FIELDS 638d0a7
  • Release 1.1.55 7240106

1.1.54

11 June 2018

  • sanitize key names for ElasticSearch also in sub-objects #10
  • Fix req.destroy in shipFile function #8
  • fix deep clone 12287be
  • Only test for array/object if value is not null/undefined e318b51
  • fix test for LOGSENE_REMOVE_FIELDS 5016ca0

1.1.53

13 April 2018

1.1.52

12 April 2018

  • support LOGSENE_REMOVE_FIELDS environment variable to remove fields from logs cdd52cc
  • Update travis for node v8,v9 978f641
  • Release 1.1.52 9202130

1.1.50

20 September 2017

  • add env var ENABLE_JSON_ENRICHMENT (default = true) ecc9631
  • Release 1.1.50 dbb174d

1.1.49

30 August 2017

  • Release 1.1.49 7764d04
  • fix TypeError: string must be a string, Buffer, or ArrayBuffer e432f67

1.1.48

6 July 2017

  • don't use disk buffer/retransmit for invalid tokens or app limits 3b5aec5
  • Release 1.1.48 3cf21c8

1.1.47

5 July 2017

  • support /etc/sematext/receivers.config for LOGSENE_RECEIVER_URL fee8cb5
  • remove file from disk-buffer when token is invalid (retransmit) 6ed81d3
  • move debug message bcb5336

1.1.46

8 June 2017

  • add test for 'unknown tokens don't use disk buffer' 190c094
  • Release 1.1.46 885825f
  • increase interval to sync diskBuffer with fs 60efeac

1.1.45

8 June 2017

1.1.44

25 May 2017

  • no disk buffer for invalid tokens 81816d0
  • update 403, application limit test 2201790
  • Release 1.1.44 2004f05

1.1.43

19 April 2017

1.1.42

19 April 2017

  • handle Logsene App limits as error, and buffer messages in files once limit is reached 7f6ea65
  • error handling for '403, App limits reached' 66d5584
  • Release 1.1.42 8ef27ec

1.1.41

9 February 2017

1.1.40

9 February 2017

1.1.38

26 January 2017

1.1.37

2 January 2017

  • error handling for invalid Logsene tokens 1b996c4
  • Release 1.1.37 15035cd

1.1.36

11 November 2016

  • place _index function after timestamp corrections 3f33492
  • Release 1.1.36 2274823

1.1.35

11 November 2016

  • fix #5 Index conditional on message for Elasticsearch #5
  • Release 1.1.35 94a4246

1.1.34

11 November 2016

1.1.33

4 November 2016

  • use /TOKEN/bulk only when URL contains logsene, else /bulk for Elasticsearch bfb92ab
  • Release 1.1.33 9061449

1.1.32

4 November 2016

  • option to use /_bulk for ES, add url to error event 6e85e36
  • Release 1.1.32 bfb9c00

1.1.31

3 November 2016

  • changed scope of request variable to support multiple instances using https or http 3a100fa
  • Release 1.1.31 6ff9b3f

1.1.29

30 September 2016

1.1.28

19 September 2016

  • set defaults: http timeout to 1 min, MAX_CLIENT_SOCKETS=2, code format with 'standard' 9b74359
  • Release 1.1.28 ff518a1

1.1.27

8 September 2016

1.1.26

8 September 2016

  • move closing buffer-stream to send() function d35b4e3
  • Release 1.1.26 0559cdd

1.1.25

7 September 2016

  • increase default log interval to 20 seconds 08aabca
  • Release 1.1.25 c4bf652

1.1.24

7 September 2016

  • changed socket options for request dc30185
  • diskBuffer / retransmit improvements 8e9db8d
  • limit message field size (240k) default 55e3b85

1.1.18

11 July 2016

  • add tests for URL set, include token, make sure _bulk is present da9cd36
  • add x-logsene-origin header 33edaa3
  • add _bulk, when only host:port is specified 29e25de

1.1.14

5 July 2016

  • fix index postion 2727ce4
  • fix RSS memory, stream/socket closing 18626cd
  • standardized (syntax check/format), fix typo ffd5ff6

1.1.0

12 June 2016

  • fix memory leak, use stream-buffers instead of strings, removed http bodies from events afb6b24
  • increased mem limit in test 16m MB, + URL for test receiver 4cdb051
  • fix test, done() called multiple times be1995b

1.0.27

30 May 2016

  • configurable interval for retransmit check 2e05052
  • version bump 80470a2
  • tuning timeouts in test aa3dfd7

1.0.25

30 May 2016

  • Fixed bug with not returning the function of the safeCycles (would re… #3
  • Handle circular logging and undefined tokens #2
  • add browser version logsene-js-bundle.js, and command npm run bundle to create the file a61988e
  • remove browser bundel from git 0767771
  • refactoring disk buffer for better tests 78762a7