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

Фильтрация мусорных логов #1420

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from

Conversation

TeterinaSvetlana
Copy link
Contributor

@TeterinaSvetlana TeterinaSvetlana commented Mar 17, 2023

Summary by CodeRabbit

  • New Features

    • Enhanced error message filtering and logging functionality.
    • Introduced a centralized method for determining log message processing.
  • Improvements

    • Expanded filters for specific debug and deprecation messages.
    • Streamlined message construction for consistency across log levels.

blueprints/ember-flexberry/index.js Outdated Show resolved Hide resolved
addon/services/log.js Outdated Show resolved Hide resolved
addon/services/log.js Outdated Show resolved Hide resolved
addon/services/log.js Outdated Show resolved Hide resolved
addon/services/log.js Outdated Show resolved Hide resolved
addon/services/log.js Outdated Show resolved Hide resolved
addon/services/log.js Outdated Show resolved Hide resolved
addon/services/log.js Show resolved Hide resolved
addon/services/log.js Outdated Show resolved Hide resolved
addon/services/log.js Outdated Show resolved Hide resolved
@sonarcloud
Copy link

sonarcloud bot commented Mar 17, 2023

SonarCloud Quality Gate failed.    Quality Gate failed

Bug C 1 Bug
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

No Coverage information No Coverage information
0.0% 0.0% Duplication

@TeterinaSvetlana TeterinaSvetlana changed the base branch from feature-ember-update to develop October 23, 2024 09:45
@TeterinaSvetlana
Copy link
Contributor Author

актуально? @pepelyaeva

Copy link

coderabbitai bot commented Oct 23, 2024

Walkthrough

The changes in the pull request focus on the LogService class within addon/services/log.js. A new method, _checkMessageOnSkipped, has been introduced to streamline the filtering of log messages based on specific conditions. This method is utilized in the existing logging functions (error, warn, log, info, debug) to determine whether to process or skip messages. Additionally, the errorMessageFilters have been expanded, and the inline filtering logic in the _storeToApplicationLog method has been removed for improved clarity and maintainability.

Changes

File Change Summary
addon/services/log.js - Added method _checkMessageOnSkipped(category, message) for centralized log message filtering.
- Expanded errorMessageFilters to include more filters for debug and deprecation messages.
- Modified _storeToApplicationLog to delegate filtering to _checkMessageOnSkipped.
- Updated logging methods to use joinArguments for consistent message string construction.

Poem

In the logs where messages play,
A rabbit hops and clears the way.
With filters new and checks so neat,
Each log now dances, oh so sweet!
Hooray for clarity, let’s all cheer,
For better logs, we hold so dear! 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Outside diff range and nitpick comments (1)
addon/services/log.js (1)

Line range hint 414-521: Consider refactoring logging methods to reduce code duplication

The _checkMessageOnSkipped checks and the subsequent logging logic are repeated across multiple Ember.Logger methods (error, warn, log, info, debug). To improve maintainability, consider abstracting the common logic into a separate function or helper. This will reduce code duplication and make future updates easier.

For example, you could create a new method that handles the message processing:

_processLogMessage(originalMethod, category, args) {
  originalMethod(...args);
  const message = joinArguments(...args);
  if (this._checkMessageOnSkipped(category, message)) return;
  return this._queue.attach((resolve, reject) => {
    return this._storeToApplicationLog(category, message, '').then((result) => {
      resolve(result);
    }).catch((reason) => {
      reject(reason);
    });
  });
}

Then update each Ember.Logger method to use this helper:

Ember.Logger.error = function() {
-  originalEmberLoggerError(...arguments);
-  const message = joinArguments(...arguments);
-  if (_this._checkMessageOnSkipped(messageCategory.error, message)) return;
-  return _this._queue.attach((resolve, reject) => {
-    return _this._storeToApplicationLog(messageCategory.error, message, '').then((result) => {
-      resolve(result);
-    }).catch((reason) => {
-      reject(reason);
-    });
-  });
+  _this._processLogMessage(originalEmberLoggerError, messageCategory.error, arguments);
};

Repeat similar changes for the other logging methods.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between d1c7d81 and 392bd34.

📒 Files selected for processing (1)
  • addon/services/log.js (7 hunks)
🧰 Additional context used
🔇 Additional comments (7)
addon/services/log.js (7)

363-368: LGTM

The additions to the errorMessageFilters array appropriately include additional messages to be filtered, enhancing the log filtering mechanism.


414-416: Adding message skip check to Ember.Logger.error

The inclusion of _this._checkMessageOnSkipped in the Ember.Logger.error method ensures that error messages are filtered according to the configured criteria before being logged.


437-442: Properly filtering deprecation and warning messages in Ember.Logger.warn

The addition of _this._checkMessageOnSkipped checks for both deprecation and warning messages in the Ember.Logger.warn method enhances the consistency of message filtering.


449-450: Ensuring warning messages are conditionally logged

The check for _this._checkMessageOnSkipped for warning messages within the else block of Ember.Logger.warn aligns with the intended selective logging behavior.


471-473: Incorporating skip check in Ember.Logger.log

Including _this._checkMessageOnSkipped in the Ember.Logger.log method allows for proper filtering of log messages based on the configuration.


494-496: Implementing message filtering in Ember.Logger.info

The addition of the _this._checkMessageOnSkipped check in the Ember.Logger.info method ensures informational messages are appropriately filtered.


517-519: Filtering debug messages in Ember.Logger.debug

Adding _this._checkMessageOnSkipped in the Ember.Logger.debug method correctly applies the filtering criteria to debug messages.

Comment on lines +689 to +695
if (errorMessageFilterActive) {
errorMessageFilters.forEach(errorMessageFilter => {
if (category.name === errorMessageFilter.category && message.indexOf(errorMessageFilter.message) !== -1) {
isSkippedMessage = true;
}
});
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Optimize error message filtering with some method

In _checkMessageOnSkipped (lines 689-695), to improve performance and readability, consider replacing the forEach loop with the some method. This change allows the iteration to exit early when a matching filter is found.

Apply this diff to implement the change:

        if (errorMessageFilterActive) {
-          errorMessageFilters.forEach(errorMessageFilter => {
-            if (category.name === errorMessageFilter.category && message.indexOf(errorMessageFilter.message) !== -1) {
-              isSkippedMessage = true;
-            }
-          });
+          isSkippedMessage = errorMessageFilters.some(errorMessageFilter =>
+            category.name === errorMessageFilter.category &&
+            message.indexOf(errorMessageFilter.message) !== -1
+          );
        }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (errorMessageFilterActive) {
errorMessageFilters.forEach(errorMessageFilter => {
if (category.name === errorMessageFilter.category && message.indexOf(errorMessageFilter.message) !== -1) {
isSkippedMessage = true;
}
});
}
if (errorMessageFilterActive) {
isSkippedMessage = errorMessageFilters.some(errorMessageFilter =>
category.name === errorMessageFilter.category &&
message.indexOf(errorMessageFilter.message) !== -1
);
}

Comment on lines +669 to +683
_checkMessageOnSkipped(category, message) {
if (!this.get('enabled') ||
category.name === messageCategory.error.name && !this.get('storeErrorMessages') ||
category.name === messageCategory.warn.name && !this.get('storeWarnMessages') ||
category.name === messageCategory.log.name && !this.get('storeLogMessages') ||
category.name === messageCategory.info.name && !this.get('storeInfoMessages') ||
category.name === messageCategory.debug.name && !this.get('storeDebugMessages') ||
category.name === messageCategory.deprecate.name && !this.get('storeDeprecationMessages') ||
category.name === messageCategory.promise.name && !this.get('storePromiseErrors')) {
new RSVP.Promise((resolve) => {
this._triggerEvent(category.name);
resolve();
});
return true;
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Remove unnecessary Promise creation in _checkMessageOnSkipped

In the _checkMessageOnSkipped method (lines 669-683), the RSVP.Promise created at lines 678-681 is unnecessary as it is not used or returned. You can remove the Promise creation and directly call _triggerEvent.

Apply this diff to fix the issue:

        if (!this.get('enabled') ||
        category.name === messageCategory.error.name && !this.get('storeErrorMessages') ||
        category.name === messageCategory.warn.name && !this.get('storeWarnMessages') ||
        category.name === messageCategory.log.name && !this.get('storeLogMessages') ||
        category.name === messageCategory.info.name && !this.get('storeInfoMessages') ||
        category.name === messageCategory.debug.name && !this.get('storeDebugMessages') ||
        category.name === messageCategory.deprecate.name && !this.get('storeDeprecationMessages') ||
        category.name === messageCategory.promise.name && !this.get('storePromiseErrors')) {
-          new RSVP.Promise((resolve) => {
-            this._triggerEvent(category.name);
-            resolve();
-          });
+          this._triggerEvent(category.name);
          return true;
        }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
_checkMessageOnSkipped(category, message) {
if (!this.get('enabled') ||
category.name === messageCategory.error.name && !this.get('storeErrorMessages') ||
category.name === messageCategory.warn.name && !this.get('storeWarnMessages') ||
category.name === messageCategory.log.name && !this.get('storeLogMessages') ||
category.name === messageCategory.info.name && !this.get('storeInfoMessages') ||
category.name === messageCategory.debug.name && !this.get('storeDebugMessages') ||
category.name === messageCategory.deprecate.name && !this.get('storeDeprecationMessages') ||
category.name === messageCategory.promise.name && !this.get('storePromiseErrors')) {
new RSVP.Promise((resolve) => {
this._triggerEvent(category.name);
resolve();
});
return true;
}
_checkMessageOnSkipped(category, message) {
if (!this.get('enabled') ||
category.name === messageCategory.error.name && !this.get('storeErrorMessages') ||
category.name === messageCategory.warn.name && !this.get('storeWarnMessages') ||
category.name === messageCategory.log.name && !this.get('storeLogMessages') ||
category.name === messageCategory.info.name && !this.get('storeInfoMessages') ||
category.name === messageCategory.debug.name && !this.get('storeDebugMessages') ||
category.name === messageCategory.deprecate.name && !this.get('storeDeprecationMessages') ||
category.name === messageCategory.promise.name && !this.get('storePromiseErrors')) {
this._triggerEvent(category.name);
return true;
}

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

Successfully merging this pull request may close these issues.

3 participants