1.0.0-0 • Published 3 years ago

@talend/log v1.0.0-0

Weekly downloads
3
License
Apache-2.0
Repository
github
Last release
3 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

3 years ago

0.189.0

4 years ago

0.188.0

4 years ago

0.187.1

4 years ago

0.187.0

4 years ago

0.186.0

4 years ago

0.185.0

4 years ago

0.184.0

4 years ago

0.183.0

4 years ago

0.182.0

4 years ago

0.181.0

4 years ago

0.180.0

4 years ago

0.179.0

4 years ago

0.178.0

4 years ago

0.177.0

4 years ago

0.176.0

4 years ago

0.175.0

4 years ago

0.174.0

4 years ago

0.173.0

4 years ago

0.172.0

4 years ago

0.171.0

4 years ago

0.170.0

4 years ago

0.169.0

4 years ago

0.168.0

4 years ago

0.167.0

4 years ago

0.166.0

4 years ago

0.165.0

4 years ago

0.164.0

4 years ago

0.163.1

4 years ago

0.163.0

4 years ago

0.162.0

4 years ago

0.161.0

4 years ago

0.160.0

4 years ago

0.159.0

4 years ago

0.158.0

4 years ago

0.157.0

4 years ago

0.156.0

4 years ago

0.155.3-0

4 years ago

0.155.1

4 years ago

0.155.2-0

4 years ago

0.155.1-0

4 years ago

0.155.0

4 years ago

0.154.0

4 years ago

0.153.0

4 years ago

0.152.0

4 years ago

0.151.0

4 years ago

0.150.0

4 years ago

0.149.0

4 years ago

0.148.0

4 years ago

0.147.0

4 years ago

0.146.0

4 years ago

0.145.0

4 years ago

0.144.0

4 years ago

0.143.0

4 years ago

0.142.0

4 years ago

0.141.0

4 years ago

0.140.0

4 years ago

0.139.0

4 years ago

0.138.0

4 years ago

0.137.0

4 years ago

0.136.0

4 years ago

0.135.0

4 years ago

0.134.0

4 years ago

0.133.0

4 years ago

0.132.0

4 years ago

0.131.0

4 years ago

0.130.0

4 years ago

0.129.0

4 years ago

0.128.0

4 years ago

0.127.0

4 years ago

0.126.0

4 years ago

0.125.0

4 years ago

0.124.0

4 years ago

0.123.0

4 years ago

0.122.0

4 years ago

0.121.0

4 years ago

0.120.0

4 years ago

0.119.0

4 years ago

0.118.0

4 years ago

0.117.0

4 years ago

0.116.0

4 years ago

0.115.0

4 years ago

0.114.0

4 years ago

0.113.1

4 years ago

0.113.0

4 years ago

0.112.0

4 years ago

0.111.0

4 years ago

0.110.0

4 years ago

0.109.0

4 years ago

0.108.0

4 years ago

0.107.0

4 years ago

0.106.1

4 years ago

0.106.0

4 years ago

0.105.0

4 years ago

0.104.0

4 years ago

0.103.0

4 years ago

0.102.4

4 years ago

0.102.3

4 years ago

0.102.1

4 years ago

0.102.0

4 years ago

0.101.0

4 years ago

0.100.0

4 years ago

0.99.0

4 years ago

0.98.0

5 years ago

0.97.1

5 years ago

0.97.0

5 years ago

0.96.0

5 years ago

0.95.0

5 years ago

0.94.0

5 years ago

0.93.0

5 years ago

0.92.0

5 years ago

0.91.0

5 years ago

0.90.0

5 years ago

0.89.0

5 years ago

0.88.0

5 years ago

0.87.0

5 years ago

0.86.0

5 years ago

0.85.1

5 years ago

0.85.0

5 years ago

0.84.0

5 years ago

0.83.1

5 years ago

0.83.0

5 years ago

0.82.0

5 years ago

0.81.0

5 years ago

0.80.0

5 years ago

0.79.0

5 years ago

0.78.0

5 years ago

0.77.0

5 years ago