1.0.0-0 • Published 5 years ago

@talend/log v1.0.0-0

Weekly downloads
3
License
Apache-2.0
Repository
github
Last release
5 years ago

Talend-log - error logging library

A small library that provides a centralized error logger.

Minimum-config usage:

Breaking changes log

Before 1.0, @talend/log does NOT follow semver version in releases. You will find a list of breaking changes here. Before 2.0, we will try not to introduce breaking changes, as possible. After 2.0, we will only introduce breaking changes in major releases, and follow semver.

Advanced config

Look in ./src/errorTransformer.js for jsDoc on each parameter

import LOGGING_SERVER_URL from 'somewhere';
import { initErrorTransformer, TraceKit } from '@talend/log';

initErrorTransformer(
    LOGGING_SERVER_URL, {
        send: (payload, fetchOptions) => fetch(LOGGING_SERVER_URL, {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json'
            },
            body: JSON.stringify({
                '@message': payload
            }),
            ...fetchOptions,
        }),
        payloadMiddleware: payload => Object.assign({
            state: TraceKit.store.getState()
        }, payload),
        fetchOptions: {
            headers: {
                'Content-Type': 'application/json',
                custom: 'customData'
            }
        },
        successHandler: (responseText) => {
            alert('yay! ' + responseText)
        },
        retryCount: 5,
        retryTimeout: 3000,
        failedTryHandler: function failedTry(error, payload, transportOpts, attempt) {
            alert('Oh no! ' + error);
            transportOpts.send(transportOpts.payloadMiddleware(payload), transportOpts.fetchOptions, attempt + 1);
        },
        failedReportHandler: (errorResponse) => {
            alert('oh no! ' + errorResponse)
        },
    }, {
        stackTraceLimit: 100,
        linesOfContext: 13,
        rethrowErrorHandler: () => {},
        remoteFetching: true,
        collectWindowErrors: true,
    }
);

TraceKit.report(new Error('My error'));

Notable details:

  • Once initErrorTransformer is called, listener function is created and registered in TraceKit, then returned.
  • Depending on the parameters you provide, TraceKit.report function may be patched to rethrow no error.
  • transport.send is called with fetchOptions defined on transport.fetchOptions
  • TraceKit.store should be defined in your configStore.js file if you want to attach state to report
  • fetchOptions are merged with Object.assign to default options, so don't expect deepMerge
  • that is also true for default transport and default options objects

Log warnings

If you have some non-critical exceptions that should be reported, but should not break application, then use a possibility to provide handler for better microcontrol:

in your config file:

import LOGGING_SERVER_URL from 'somewhere';
import initErrorTransformer from '@talend/log';
import transportConfig from 'somewhere';

// this:
initErrorTransformer(LOGGING_SERVER_URL, transportConfig, {
    rethrowErrorHandler: (e) => { if (e.type === 'critical') { throw e; } else { console.error(e); } },
})

somewhere in your application:

import { TraceKit } from '@talend/log';

fetch('google.com').catch(errorResponse => TraceKit.report(new Error(errorResponse)));

Under the hood

TraceKit - Cross browser stack traces. https://github.com/csnover/TraceKit

1.0.0-0

5 years ago

0.189.0

6 years ago

0.188.0

6 years ago

0.187.1

6 years ago

0.187.0

6 years ago

0.186.0

6 years ago

0.185.0

6 years ago

0.184.0

6 years ago

0.183.0

6 years ago

0.182.0

6 years ago

0.181.0

6 years ago

0.180.0

6 years ago

0.179.0

6 years ago

0.178.0

6 years ago

0.177.0

6 years ago

0.176.0

6 years ago

0.175.0

6 years ago

0.174.0

6 years ago

0.173.0

6 years ago

0.172.0

6 years ago

0.171.0

6 years ago

0.170.0

6 years ago

0.169.0

6 years ago

0.168.0

6 years ago

0.167.0

6 years ago

0.166.0

6 years ago

0.165.0

6 years ago

0.164.0

6 years ago

0.163.1

6 years ago

0.163.0

6 years ago

0.162.0

6 years ago

0.161.0

6 years ago

0.160.0

6 years ago

0.159.0

6 years ago

0.158.0

6 years ago

0.157.0

6 years ago

0.156.0

6 years ago

0.155.3-0

6 years ago

0.155.1

6 years ago

0.155.2-0

6 years ago

0.155.1-0

6 years ago

0.155.0

6 years ago

0.154.0

6 years ago

0.153.0

6 years ago

0.152.0

6 years ago

0.151.0

6 years ago

0.150.0

6 years ago

0.149.0

6 years ago

0.148.0

6 years ago

0.147.0

6 years ago

0.146.0

6 years ago

0.145.0

6 years ago

0.144.0

6 years ago

0.143.0

6 years ago

0.142.0

6 years ago

0.141.0

6 years ago

0.140.0

6 years ago

0.139.0

6 years ago

0.138.0

6 years ago

0.137.0

6 years ago

0.136.0

6 years ago

0.135.0

6 years ago

0.134.0

6 years ago

0.133.0

6 years ago

0.132.0

6 years ago

0.131.0

6 years ago

0.130.0

6 years ago

0.129.0

6 years ago

0.128.0

6 years ago

0.127.0

6 years ago

0.126.0

6 years ago

0.125.0

6 years ago

0.124.0

6 years ago

0.123.0

6 years ago

0.122.0

6 years ago

0.121.0

6 years ago

0.120.0

6 years ago

0.119.0

6 years ago

0.118.0

7 years ago

0.117.0

7 years ago

0.116.0

7 years ago

0.115.0

7 years ago

0.114.0

7 years ago

0.113.1

7 years ago

0.113.0

7 years ago

0.112.0

7 years ago

0.111.0

7 years ago

0.110.0

7 years ago

0.109.0

7 years ago

0.108.0

7 years ago

0.107.0

7 years ago

0.106.1

7 years ago

0.106.0

7 years ago

0.105.0

7 years ago

0.104.0

7 years ago

0.103.0

7 years ago

0.102.4

7 years ago

0.102.3

7 years ago

0.102.1

7 years ago

0.102.0

7 years ago

0.101.0

7 years ago

0.100.0

7 years ago

0.99.0

7 years ago

0.98.0

7 years ago

0.97.1

7 years ago

0.97.0

7 years ago

0.96.0

7 years ago

0.95.0

7 years ago

0.94.0

7 years ago

0.93.0

7 years ago

0.92.0

7 years ago

0.91.0

7 years ago

0.90.0

7 years ago

0.89.0

7 years ago

0.88.0

7 years ago

0.87.0

7 years ago

0.86.0

7 years ago

0.85.1

7 years ago

0.85.0

7 years ago

0.84.0

7 years ago

0.83.1

7 years ago

0.83.0

7 years ago

0.82.0

7 years ago

0.81.0

7 years ago

0.80.0

7 years ago

0.79.0

7 years ago

0.78.0

7 years ago

0.77.0

7 years ago