• If you are still using CentOS 7.9, it's time to convert to Alma 8 with the free centos2alma tool by Plesk or Plesk Migrator. Please let us know your experiences or concerns in this thread:
    CentOS2Alma discussion
  • Inviting everyone to the UX test of a new security feature in the WP Toolkit
    For WordPress site owners, threats posed by hackers are ever-present. Because of this, we are developing a new security feature for the WP Toolkit. If the topic of WordPress website security is relevant to you, we would be grateful if you could share your experience and help us test the usability of this feature. We invite you to join us for a 1-hour online session via Google Meet. Select a convenient meeting time with our friendly UX staff here.

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