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

Need examples of procesLog and filterLog #132

Closed
souravsaraf123 opened this issue Jan 30, 2022 · 8 comments
Closed

Need examples of procesLog and filterLog #132

souravsaraf123 opened this issue Jan 30, 2022 · 8 comments
Labels
bug Something isn't working

Comments

@souravsaraf123
Copy link

Hi, thanks for developing this plugin.

I am trying to use filterLog functions [i only want severity 'error' or 'warning'].

const logOptions: any = {
filterLog: (type: string, message: string, severity: string) => {
		return ['error', 'warning'].includes(severity);
	}
}
installLogsCollector(logOptions);

// THIS IS NOT WORKING

I also tried to use processLog function [i wish to add timestamps for my cy.route failure and cy.request failure logs]

const logOptions: any = {
processLog: (type: string, message: string, severity: string) => {
		let currentIsoTime = new Date().toISOString();
		let currentType = type;
		let currentMessage = message;
		let currentSeverity = severity;

		return [currentIsoTime, currentType, currentMessage, currentSeverity].join(' | ');
	}
}
installLogsCollector(logOptions);

// THIS IS NOT WORKING
@archfz
Copy link
Owner

archfz commented Jan 30, 2022

When in doubt use the browser debugger to check your parameters.

Not sure how you are bypassing type errors, as I see you use typescript, and this package has types for all configuration ...

Anyway the issues is that both those functions receive a single parameter that is an array. Please recheck the documentation and use array destrcuturing.

@archfz archfz closed this as completed Jan 30, 2022
@archfz
Copy link
Owner

archfz commented Jan 30, 2022

@souravsaraf123
Copy link
Author

I turned off typings and misread the type of function arguments.

For future readers, i made it work :

filterLog: (args: [type: string, message: string, severity: string]) => {
		let [type, pluginMessage, severity] = args;
		return ['error', 'warning'].includes(severity);
},
processLog: (args: [type: string, message: string, severity: string]) => {
		let currentIsoTime = new Date().toISOString();
		let [type, pluginMessage, severity] = args;

		let customObject = {
			type: type,
			message: `At time ${currentIsoTime}`,
			severity: severity
		};
		let resMessage =  `Custom Object ==> \n${JSON.stringify(customObject)}\nPlugin Message ==> \n${pluginMessage}`;

		return [type, resMessage, severity];
}

@souravsaraf123
Copy link
Author

@archfz :

I think, in the typings file, there are 2 mistakes ==>

filterLogs definition ((args: [/* type: / Severity, / message: / string, / severity: */ Severity]) => boolean);
Here type is given as Severity , it should be collectTypes

Same in processLogs ==>
processLogs definition ==> ((args: [/* type: / Severity, / message: / string, / severity: */ Severity]) => [Severity, string, Severity]);
Here type is given as Severity , it should be collectTypes

Anyways, thanks a lot for the plugin and the help in fixing my error 👍

@archfz
Copy link
Owner

archfz commented Jan 31, 2022

Indeed that is incorrect, I will reopen the issue for that to be fixed.

@archfz
Copy link
Owner

archfz commented Feb 6, 2022

Fixed in 3.4.2

@archfz archfz closed this as completed Feb 6, 2022
@iamskok
Copy link

iamskok commented Mar 14, 2022

@archfz Thank you for your plugin!

I think the return type should also be updated.

processLog?:
      | null
      | NonNullable<SupportOptions['collectTypes']>[number]
      | ((args: [/* type: */ LogType, /* message: */ string, /* severity: */ Severity]) => [Severity, string, Severity]);

Instead of [Severity, string, Severity] it should be [LogType, string, Severity].

@archfz archfz reopened this Mar 14, 2022
@archfz archfz added the bug Something isn't working label Mar 31, 2022
@archfz
Copy link
Owner

archfz commented Mar 31, 2022

Released in 3.5.0

@archfz archfz closed this as completed Mar 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants