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

enableLog flag not working #66

Open
balman opened this issue Jun 16, 2021 · 10 comments
Open

enableLog flag not working #66

balman opened this issue Jun 16, 2021 · 10 comments

Comments

@balman
Copy link

balman commented Jun 16, 2021

Summary

The enableLog configuration option is disregarded and log files are generated even when the value is false.

Expected Behavior

Specifying enableLog: false when creating a new API client should suppress log files from being written to. An example would be as follows:

const cybersourceRestApi = require('cybersource-rest-client')
const merchantConfig = {
  authenticationType: 'http_signature',
  runEnvironment: 'cybersource.environment.SANDBOX',
  merchantID: 'XXXXXXX',
  merchantKeyId: 'XXXXXXXXX',
  merchantsecretKey: 'XXXXXXXXXXXXXX',
  enableLog: false // this should result in logs from the CyberSource REST client being suppressed
}

const paymentsApi = new cybersourceRestApi.PaymentsApi(merchantConfig)

Actual Behavior

When enableLog: false is specified, the CyberSource REST client still writes logs to the filesystem.

Other Comments

It looks like there was a switch to using the winston-daily-rotate-file package recently, and the enableLog option from the CyberSource client is being passed to this transport as part of a silent option. However, it looks like there is no reference to a silent option in the documentation for this package and so it may not be a valid option for this transport.

@doginthehat
Copy link

Yeah same issue

@doginthehat
Copy link

doginthehat commented Jul 2, 2021

@balman I was able to go around the issue by patching the logger on the fly with my own.

I copied src/authentication/logging/Logger.js from cybersource-rest-client package to my own local copy (patch_logger.js)

Then did this to replace the logger on the fly:

const cybersourceRestApi = require('cybersource-rest-client');
const logger = require('./patch_logger.js');
cybersourceRestApi.Logger.getLogger = logger.getLogger

Then you can tweak patch_logger accordingly to make it work.

Note: silent is an option at the logger level itself, not the transporter. However, setting silent in the logger but still keeping DailyRotateFile still triggers some minor logging to file.

I ended up with this solution:

const winston = require("winston");
const { format } = require("winston");
const { combine, timestamp, label, printf } = format;
require("winston-daily-rotate-file");

const loggingFormat = printf(({ level, message, label, timestamp }) => {
	return `[${timestamp}] [${level.toUpperCase()}] [${label}] : ${message}`;
});

exports.getLogger = function (
	merchantConfig,
	loggerCategory = "UnknownCategoryLogger"
) {
	var appTransports = createTransportFromConfig(merchantConfig);

	var loggingLevel = merchantConfig.getLoggingLevel();
	var enableLog = merchantConfig.getEnableLog();
	return winston.loggers.get(loggerCategory, {
		level: loggingLevel,
		silent: !enableLog,
		format: combine(
			label({ label: loggerCategory }),
			timestamp(),
			loggingFormat
		),
		transports: appTransports,
	});
};

function createTransportFromConfig(mConfig) {
	var transports = [];

	var loggingLevel = mConfig.getLoggingLevel();
	var maxLogFiles = mConfig.getMaxLogFiles();
	var logFileName = mConfig.getLogFileName();
	var logDirectory = mConfig.getLogDirectory();
	var enableLog = mConfig.getEnableLog();

	transports.push(
		enableLog
			? new winston.transports.DailyRotateFile({
					level: loggingLevel,
					filename: logFileName + "-%DATE%.log",
					datePattern: "YYYY-MM-DD",
					zippedArchive: true,
					dirname: logDirectory,
					maxFiles: maxLogFiles,
					silent: !enableLog,
			  })
			: new winston.transports.Console({
					format: winston.format.simple({}),
			  })
	);

	return transports;
}

@balman
Copy link
Author

balman commented Jul 21, 2021

@doginthehat Thanks for sharing! This looks like a promising interim solution.

@YegorMedvedev
Copy link

The same is here... @balman any progress with the issue?

@robertop87
Copy link

The same behavior here.

In my case it's critical because I'm deploying in a serverless infrastructure, which means only read access to file system.

Here is my error (related to flag not working)
Error: EROFS: read-only file system, mkdir 'log/'

@balman is there any progress to solve this?

@doginthehat
Copy link

@robertop87 We had the same problem. We were able to go around by patching the logger as per previous comment.

It's really disappointing to see how little care Cybersource is giving to this node client, we've had so many issues. 🙄

@merugus
Copy link

merugus commented Apr 12, 2022

Hi there,

I have used "cybersource-rest-client": "^0.0.36" and made EnableLog = false; EnableMasking = false; to resolve the issue.

-Srini

@adityaDataScientist
Copy link

adityaDataScientist commented Nov 21, 2022

@robertop87 @doginthehat are you able to resolve this issue? Actually, I am also getting the same error while creating the lambda function. Could you please let me know how I can resolve this?

@rsachan8
Copy link
Contributor

@adityaDataScientist you need to disable logging using "enableLog" flag in your client configuration.
You can refer this sample : https://github.com/CyberSource/cybersource-rest-samples-node/blob/master/Data/Configuration.js#L27

@samhithal
Copy link

Please refer to this sample : https://github.com/CyberSource/cybersource-rest-samples-node/blob/master/Data/Configuration.js#L27 @robertop87 @doginthehat @balman

Please let us know if still see the issue.

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

No branches or pull requests

8 participants