Meteor-logger-file icon indicating copy to clipboard operation
Meteor-logger-file copied to clipboard

Missing log file with Meteor Up deployment

Open shiami opened this issue 5 years ago • 4 comments

My setup:

import { Logger }     from 'meteor/ostrio:logger';
import { LoggerFile } from 'meteor/ostrio:loggerfile';
import { LoggerConsole } from 'meteor/ostrio:loggerconsole';

const log = new Logger();
new LoggerConsole(log).enable();
new LoggerFile(log, {
    path: './logs/'
  }).enable({
    enable: true,
    filter: ['*'], // Filters: 'ERROR', 'FATAL', 'WARN', 'DEBUG', 'INFO', 'TRACE', '*'
    client: false, // Set to `false` to avoid Client to Server logs transfer
    server: true  // Allow logging on server
  });

It works at local meteor. After mup deploy, the folder appears at /built_app/programs/server/logs, but the log file never show up.

shiami avatar Jun 29 '20 09:06 shiami

Hey 👋 @shiami Two possible reasons:

  1. Path not writable;
  2. Directory got gleaned up.

To solve it I suggest creating and using /data/logs directory. Better if configured with mup as storage

dr-dimitru avatar Jun 29 '20 15:06 dr-dimitru

FYI this also occurs if you are not properly calling upon your log methods.

log.warn("message", {my: 'object'), userId);  // where userId comes from meteor or etc.

if you do not use the built in methods as per base class: https://github.com/veliovgroup/Meteor-logger Then the folder exists and no files or output whatsoever.

I had presumed, not sure why, that using console.log() would redirect to it. It does not. Also tried tag teaming ostrio:logger-console on the same Logger base class. But to no avail.

Here's my helper class which completely ignores meteor's user. I imagine this would be considered an anti-pattern. But I don't use Meteor sessions, and I value a global common logging system far more than importing a logger constant everywhere. so. yea.


let self = null;

class Console {
    constructor(log) {
        self = this;
        this._log = log;

        this.hooked = {
            warn: console.warn,
            error: console.error,
            info: console.info,
            log: console.log,
            debug: console.debug,
            dir: console.dir
        };
        // apply hooks...
        console.warn = this.warn;
        console.error = this.error;
        console.info = this.info;
        console.log = this.log;
        console.debug = this.debug;
        console.dir = this.dir;
    }

    warn() {
        let details = self.common_getDetails.apply(self, arguments);
        self._log.warn(details.msg, details.data, 0);
        return self.hooked.warn.apply(this, arguments);
    }
    error() {
        let details = self.common_getDetails.apply(self, arguments);
        self._log.error(details.msg, details.data, 0);
        return self.hooked.error.apply(this, arguments);
    }
    info() {
        let details = self.common_getDetails.apply(self, arguments);
        self._log.info(details.msg, details.data, 0);
        return self.hooked.info.apply(this, arguments);
    }
    log() {
        let details = self.common_getDetails.apply(self, arguments);
        self._log.info(details.msg, details.data, 0);
        return self.hooked.log.apply(this, arguments);
    }
    debug() {
        let details = self.common_getDetails.apply(self, arguments);
        self._log.debug(details.msg, details.data, 0);
        return self.hooked.debug.apply(this, arguments);
    }

    
    dir() {
        return self.hooked.dir.apply(this, arguments);
    }

    common_getDetails() {
        let msg = '';
        let data = null;
        if (typeof(arguments[0])=='string') {
            msg = arguments[0];
            if (arguments.length>1 && typeof(arguments[1])!=='string') {
                data = arguments[1]; // todo: consider a clone and splice? actually slice would be smarter.
            }
        }
        else {
            data = arguments;
        }
        return {
            msg: msg,
            data: data
        };
    }

}
export default Console;

// then wherever you initialize your logger globally (singleton):

import { Logger } from 'meteor/ostrio:logger';
import { LoggerConsole } from 'meteor/ostrio:loggerconsole';
import { LoggerFile } from 'meteor/ostrio:loggerfile';
import Console from './console';

const log = new Logger();
// formatting, config, etc, goes here, for logger and loggerfile/loggerconsole.
const _console = new Console(log);

common_getDetails needs help, considering all the possible variations of arguments. But it does the job at a simple level.

Meaning you can call "console.log" naturally like you always do, and it goes both to console output (natural), and to your ostrio logger file.

ensemblebd avatar Aug 17 '21 23:08 ensemblebd

I had presumed, not sure why, that using console.log() would redirect to it. It does not.

This is never a case, you got to use Logger methods

dr-dimitru avatar May 31 '22 20:05 dr-dimitru

Please see and upgrade to the latest v2.1.0

Feel free to close it in case if the issue is solved on your end.

dr-dimitru avatar Jun 01 '22 17:06 dr-dimitru