/**
* Filters log stream data for staging environments, supporting older versions.
*
* @param {Array<Object>} logs - An array of log objects. Each object is expected to have a 'environment' and 'version' property.
* @param {string} targetEnvironment - The target environment to filter for (e.g., 'staging').
* @param {string} minVersion - The minimum supported version (e.g., '1.0'). Older versions will be excluded.
* @returns {Array<Object>} - An array containing only the log objects from the specified environment and version.
*/
function filterLogStreams(logs, targetEnvironment, minVersion) {
if (!Array.isArray(logs)) {
return []; // Return empty array if input is not an array
}
const filteredLogs = logs.filter(log => {
// Check if the log object has the required properties
if (!log.environment || !log.version) {
return false; // Skip logs without environment or version
}
// Compare the environment and version
return log.environment === targetEnvironment && log.version >= minVersion;
});
return filteredLogs;
}
//Example Usage (for testing)
// const logs = [
// { environment: 'staging', version: '1.1' },
// { environment: 'production', version: '2.0' },
// { environment: 'staging', version: '1.0' },
// { environment: 'staging', version: '1.2' },
// { environment: 'staging', version: '0.9' }
// ];
// const filtered = filterLogStreams(logs, 'staging', '1.0');
// console.log(filtered);
Add your comment