Need examples of procesLog and filterLog
souravsaraf123 opened this issue · 8 comments
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
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.
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];
}
@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 👍
Indeed that is incorrect, I will reopen the issue for that to be fixed.
Fixed in 3.4.2
@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]
.
Released in 3.5.0