• Plesk Uservoice will be deprecated by October. Moving forward, all product feature requests and improvement suggestions will be managed through our new platform Plesk Productboard.
    To continue sharing your ideas and feedback, please visit features.plesk.com

Question Error logs Phusion Passenger nginx Nodejs

LukasBe

New Pleskian
Hello Plesk-Community,

I have a NodeJs-App running with Phusion Passenger and nginx on Plesk.
The instructions for the passenger configuration to setup a path for the log files isn't working in my case.

Is there anybody who knows how to setup up error logs?

I have apended my config file.

Thank you in advance.

Kind regards
Lukas


passenger_root /usr/share/passenger/phusion_passenger/locations.ini;

# Avoid downloading of sources or binary for ruby passenger_native_support.so
# after each nginx restart by default because of development packages
# or libruby.so.X.Y may be missed anyway.
# Ruby passenger_native_support.so is packaged for system ruby only.
passenger_env_var PASSENGER_COMPILE_NATIVE_SUPPORT_BINARY 0;
passenger_env_var PASSENGER_DOWNLOAD_NATIVE_SUPPORT_BINARY 0;
passenger_log_file /var/log/passenger_log/passenger.log
 
My solution

// initErrorLogs.js

import path from 'path';
import fs from 'fs';
import util from 'util';

var log_file = fs.createWriteStream(path.resolve('node.log'), {flags : 'w'});
var log_stdout = process.stdout;

const formatDate = (date = new Date()) => {
var year = date.getFullYear(),
month = date.getMonth() + 1, // months are zero indexed
day = date.getDate(),
hour = date.getHours(),
minute = date.getMinutes(),
second = date.getSeconds(),
hourFormatted = hour % 12 || 12, // hour returned in 24 hour format
minuteFormatted = minute < 10 ? "0" + minute : minute;

return day + "." + month + "." + year + " - " + hourFormatted + ":" + minuteFormatted;
}

var _log = console.log;

console.log = function(...args){
var output = args.join(' ');

if(!output.includes('SyncedCron'))
log_file.write('['+ formatDate() +' | console.log] '+ util.format(output) + '\r\n');

_log.apply(console,args);
};

process.on('uncaughtException', (err) => {
log_file.write('['+ formatDate() +' | uncaughtException] '+ util.format(err) + '\r\n');
log_stdout.write(util.format(err) + '\r\n');
});

process.on('warning', (warning) => {
log_file.write('['+ formatDate() +' | warning] '+ util.format(warning) + '\r\n');
});

process.on('unhandledRejection', (reason, promise) => {
log_file.write('['+ formatDate() +' | unhandledRejection] '+ util.format({promise, reason}) + '\r\n');
});

process.on('message', (message, sendHandle) => {
log_file.write('['+ formatDate() +' | message] '+ util.format({message, sendHandle}) + '\r\n');
});
 
Hi LukasBe,

are you still going with your own log-solution?

The instructions for the passenger configuration to setup a path for the log files isn't working in my case either (PassengerLogFile).

Anyone has a different solution?
 
Back
Top