How to use winston-uber - 7 common examples

To help you get started, we’ve selected a few winston-uber examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github uber / sentry-logger / index.js View on Github external
function SentryLogger(options) {
    if (!(this instanceof SentryLogger)) {
        return new SentryLogger(options);
    }

    winston.Transport.call(this, options);
    this.name = 'SentryLogger';
    this.level = options.level || 'error';
    this.enabled = typeof(options.enabled) === 'boolean' ?
        options.enabled : true;
    this.dsn = options.dsn;
    this.defaultTags = options.tags || {};
    this.computeErrLoc = options.computeErrLoc || computeErrLoc;

    if (!this.defaultTags.pid) {
        this.defaultTags.pid = process.pid;
    }

    var ravenErrorHandler = typeof options.onRavenError === 'function' ?
        options.onRavenError : function (e) {
            // do not warn() on 429 errors
            if (e.message.indexOf('429') >= 0) {
github uber / kafka-logger / index.js View on Github external
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

/* jshint forin: false */
var util = require('util');
var Transport = require('winston-uber').Transport;
var KafkaRestClient = require('kafka-rest-client');
var hostName = require('os').hostname();
var extend = require('xtend');

function KafkaLogger(options) {
    if (!(this instanceof KafkaLogger)) {
        return new KafkaLogger(options);
    }

    var self = this;

    function onConnect(err) {
        if (!err) {
            if (self.logger) {
                self.logger.info('KafkaClient connected to kafka');
            }
github uber / sentry-logger / index.js View on Github external
this.captureMessage = this.ravenClient.captureMessage
        .bind(this.ravenClient);
    this.sentryProber = options.sentryProber || null;
    this.sentryProberCallbackImmediately = !options.sentryProberDetectFailuresBy;
    this.sentryProberDetectFailuresByCallback = options.sentryProberDetectFailuresBy === SentryLogger.detectBy.CALLBACK;
    this.sentryProberDetectFailuresByEvent = options.sentryProberDetectFailuresBy === SentryLogger.detectBy.EVENT;
    this.sentryProberDetectFailuresByEventSuccessEvent = options.sentryProberDetectFailuresByEventSuccessEvent;
    this.sentryProberDetectFailuresByEventFailureEvent = options.sentryProberDetectFailuresByEventFailureEvent;
}

SentryLogger.detectBy = {
    CALLBACK: 'callback',
    EVENT: 'event'
};

util.inherits(SentryLogger, winston.Transport);

SentryLogger.prototype.name = 'SentryLogger';

SentryLogger.prototype.log = function(level, msg, meta, callback) {
    var thunk;

    if (!meta || typeof meta !== 'object') {
        meta = {};
    }
    // store original meta because we might serialize it
    var originalMeta = meta;
    var stringMeta = stringify(meta);

    // To avoid sending circular data to sentry we check
    // whether its circular using json-stringify-safe and then
    // stringify(parse(meta)) to make it not circular
github uber / sentry-logger / index.js View on Github external
options.onRavenError : function (e) {
            // do not warn() on 429 errors
            if (e.message.indexOf('429') >= 0) {
                return;
            }

            winston.warn('Raven failed to upload to Sentry: ', {
                message: e.message,
                stack: e.stack,
                reason: e.reason,
                statusCode: e.statusCode
            });
        };
github uber / sentry-logger / test / works-with-winston.js View on Github external
test('SentryLogger error msg formatting', function (assert) {
    var messages = [];
    var sLogger = new SentryLogger({
        ravenClient: fakeRavenClient(function () {
            messages.push([].slice.call(arguments));
        })
    });

    var logger = new Logger({
        transports: [ sLogger ]
    });

    logger.error('oops');

    assert.equal(messages[0][1], 'works-with-winston.js: oops');

    assert.end();
});
github uber / sentry-logger / test / lib / create-logger.js View on Github external
if (typeof opts === 'function') {
        listener = opts;
        opts = {};
    }

    var server;

    opts = opts || {};

    if (!opts.dsn) {
        server = SentryServer(listener);
        opts.dsn = server.dsn;
    }

    var sLogger = new SentryLogger(opts);
    var logger = new Logger({
        transports: [ sLogger ]
    });

    logger.destroy = function () {
        if (server) {
            server.close();
        }
    };

    return logger;
}
github uber / kafka-logger / index.js View on Github external
self.logger.info('KafkaRestClient connected to kafka');
            }
            self.kafkaRestClientConnected = true;
            if (!this.kafkaClient || (this.kafkaClient && this.connected)) {
                self._flush();
            }
        } else {
            if (self.logger) {
                self.logger.warn('KafkaRestClient could not connect to kafka');
            }
        }
    }

    options = options || {};

    Transport.call(this, options);
    this.topic = options.topic || 'unknown';
    this.leafHost = options.leafHost;
    this.leafPort = options.leafPort;
    this.proxyHost = options.proxyHost || 'localhost';
    if ('proxyPort' in options && options.proxyPort) {
        this.proxyPort = options.proxyPort;
    }
    this.logger = options.logger;
    this.properties = options.properties || {};
    this.dateFormats = options.dateFormats || { isodate: 'iso' };
    this.peerId = options.hasOwnProperty('peerId') ? options.peerId : -1;
    this.workerId = options.hasOwnProperty('workerId') ? options.workerId : -1;
    this.logTemplate = {
        host: hostName,
        level: "LOGLEVELHERE",
        msg: "MESSAGEHERE"

winston-uber

A multi-transport async logging library for Node.js

MIT
Latest version published 8 years ago

Package Health Score

67 / 100
Full package analysis