Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log4js weird behavior #138

Open
isakar opened this issue May 5, 2016 · 6 comments
Open

Log4js weird behavior #138

isakar opened this issue May 5, 2016 · 6 comments
Labels

Comments

@isakar
Copy link

isakar commented May 5, 2016

Hi, I have a project in which I am using log4js to track the processes in a log file and it works fine without NAR package, but when I create the package with NAR (I added all my dependencies in package.json) and execute it, the project still runs well but the there is no log file and It doesn't show an error, nothing to tell me what could be is happening. Do you have any thought about it?

@h2non
Copy link
Owner

h2non commented May 5, 2016

nar executables is a bash process that creates a child process to run the node process. You're issue could be related to OS specific processes? In terms of logging, you should be able to write log entries into a file or to stderr/stdout stream without problems.

@h2non h2non added question and removed enhancement labels May 5, 2016
@isakar
Copy link
Author

isakar commented May 5, 2016

I am using a mac with OS X El Capitan and the final deploy would be over Amazon C2 server. The log file would be created in the same level as the routes folder but in a log folder and log4js creates the file where I specify in a configuration section with 'filename' parameter. I have something like this:
config.js

var log4js = require('log4js');
log4js.loadAppender('file');
log4js.configure({
    appenders: [
        {   type: 'file',
            filename: "./logs/pbws.log", 
            category: 'Logs',
            maxLogSize: 20480,
            backups: 10
        }
    ]
});

var logger;
var getLogger = function(name, callback){
    logger = log4js.getLogger(name);
    logger.setLevel("Logs");
    callback(logger);
};
exports.getLogger = getLogger;

In other files I use this like:

var config = require('./config');
var logger;
config.getLogger("NameX", function(log){
    logger = log;
});

logger.debug('My text for the log file');

@isakar
Copy link
Author

isakar commented May 5, 2016

Also, I am doing another quick test with this example:

var fs = require('fs');
        var stream = fs.createWriteStream("MyFile.txt");
        stream.once('open', function(fd) {
          stream.write("Row 1 writing\n");
          stream.write("Next row\n");
          stream.end();
        });

But the file doesn't create anywhere when I run the project with NAR. So the issue is not just the Log4js, is probably the paths mapping.

@aledbf
Copy link

aledbf commented May 5, 2016

@isakar you can use lsof -p <pid of nar run> to see what files (with full path) are open

@isakar
Copy link
Author

isakar commented May 5, 2016

I can see this in the console:
node 50478 SakarI 22w REG 1,4 2752 15317040 /private/var/folders/79/pybn74xx6h9f97v3s_4m54cc0006by/T/nar-PictureBookWS-0.0.1-1462473651036/logs/pbws.log

Actually is the name of my log, but I don't know how could I get it. I mean, if I search in the entire computer, it doesn't find the file in nowhere.

@h2non
Copy link
Owner

h2non commented May 5, 2016

Use an absolute path or an explicit extraction path. nar by defaults extracts files in .nar hidden folder.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants