Serge Serge - 10 months ago 76
Node.js Question

Firebase functions: logging with winston in stackdriver console

I cannot make winston logger to write logs to stackdriver console. I deploy my functions as google firebase functions (using

logging works fine, but we don't use such tool in the project.

What I tried:

Please suggest... I'm tired of experiments (each re-deploy takes time)

Answer Source

Finally what I did - implemented custom transport which actually calls console.log under the hood. This helped.

const winston = require('winston');
const util = require('util');
const ClassicConsoleLoggerTransport = winston.transports.CustomLogger = function (options) {
    options = options || {}; = '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);
        case 'notice':
        case 'info':
  , args);
        case 'warn':
        case 'warning':
            console.warn.apply(null, args);
        case 'error':
        case 'crit':
        case 'alert':
        case 'emerg':
            console.error.apply(null, args);
            console.log.apply(null, args);
    callback(null, true);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download