Firebase features: logging with winston in packdriver console

I cannot do winston logger to write logs to stackdriver . I am deploying my functions as google firebase functions (using firebase deploy

). console

works well, but we are not using this tool in the project.

What I have tried:

Please suggest ... I'm tired of experimenting (every redeploy takes time)

+3


source to share


1 answer


Finally, what I did was implement a custom transport that actually calls console.log

under the hood. That helped.



const winston = require('winston');
const util = require('util');
const ClassicConsoleLoggerTransport = winston.transports.CustomLogger = function (options) {
    options = options || {};
    this.name = 'ClassicConsoleLoggerTransport';
    this.level = options.level || 'info';
    // Configure your storage backing as you see fit
};
util.inherits(ClassicConsoleLoggerTransport, winston.Transport);

ClassicConsoleLoggerTransport.prototype.log = function (level, msg, meta, callback) {
    let args = [msg, '---', meta];
    switch (level) {
        case 'verbose':
        case 'debug':
            console.log.apply(null, args);
            break;
        case 'notice':
        case 'info':
            console.info.apply(null, args);
            break;
        case 'warn':
        case 'warning':
            console.warn.apply(null, args);
            break;
        case 'error':
        case 'crit':
        case 'alert':
        case 'emerg':
            console.error.apply(null, args);
            break;
        default:
            console.log.apply(null, args);
    }
    callback(null, true);
};

      

+1


source







All Articles