0.111.0 • Published 7 years ago

talend-log v0.111.0

Weekly downloads
73
License
Apache-2.0
Repository
github
Last release
7 years ago

Talend-log - error logging library

A small library that provides redux-logger middleware for error logging to be applied as errorTransformer.

Exports redux-logger compatible error logging middleware.

Minimum-config usage:

your configStore.js file:

import { createStore, applyMiddleware } from 'redux';
import thunkMiddleware from 'redux-thunk';
import promise from 'redux-promise-middleware';
import createLogger from 'redux-logger';
import LOGGING_SERVER_URL from 'somewhere';
import initErrorTransformer, { TraceKit } from 'talend-log';

// important part:
const logger = createLogger({ errorTransformer: initErrorTransformer(LOGGING_SERVER_URL) });
// :end of important part

const createStoreWithMiddleware = applyMiddleware(thunkMiddleware, promise(), logger)(createStore);
export default function configureStore(reducer, initialState) {
    const store = createStoreWithMiddleware(reducer, initialState);
    // drop a reference to store instance for later use in errorLogging reportMiddleware
    TraceKit.store = store;
    return store;
}

Advanced config

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

import LOGGING_SERVER_URL from 'somewhere';
import initErrorTransformer from 'talend-log';

const logger = createLogger({
    errorTransformer: 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,
        }
    )
});

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

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.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.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

0.76.0

7 years ago

0.75.1

7 years ago

0.75.0

7 years ago

0.74.2

7 years ago

0.74.1

7 years ago

0.74.0

7 years ago

0.73.0

7 years ago

0.72.3

7 years ago

0.72.2

7 years ago

0.72.1

7 years ago

0.72.0

7 years ago

0.71.2

7 years ago

0.71.1

7 years ago

0.71.0

7 years ago

0.70.1

7 years ago

0.70.0

7 years ago

0.69.0

7 years ago

0.68.1

7 years ago

0.68.0

7 years ago

0.67.0

7 years ago

0.66.4

7 years ago

0.66.3

7 years ago

0.66.2

7 years ago

0.66.1

7 years ago

0.66.0

7 years ago

0.65.0

7 years ago

0.64.0

7 years ago

0.63.1

7 years ago

0.63.0

7 years ago

0.0.1

7 years ago