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

feat: dont print log when running commands unless error #800

Merged
merged 1 commit into from
Dec 31, 2024

Conversation

hwbrzzl
Copy link
Contributor

@hwbrzzl hwbrzzl commented Dec 31, 2024

📑 Description

Don't print the log when running commands unless there is an error.

image

Ran installer success:

image

Summary by CodeRabbit

  • New Features

    • Added IsArtisan() function to detect Artisan environment based on command-line arguments
    • Improved logging configuration to set error level in Artisan environment
  • Refactor

    • Simplified NewApplication function by removing debug/Artisan boolean parameter
    • Centralized Artisan status determination using env.IsArtisan() method
  • Chores

    • Updated method signatures across multiple files to remove debug flags
    • Added new import for environment package

✅ Checks

  • Added test cases for my code

Copy link
Contributor

coderabbitai bot commented Dec 31, 2024

Walkthrough

The pull request introduces changes to the Goravel framework's console and environment handling. The primary modification is the removal of the boolean parameter from the NewApplication function across multiple files. Instead of explicitly passing an Artisan flag, the new implementation uses env.IsArtisan() to determine the application's environment. A new IsArtisan() function is added to the support/env/env.go package, which checks command-line arguments to detect if the application is running in Artisan mode.

Changes

File Change Summary
console/application.go Removed variadic artisan parameter from NewApplication function
console/application_test.go Updated NewApplication function call in test cases to remove boolean parameter
console/cli_helper_test.go Simplified NewApplication function call in test
console/service_provider.go Removed boolean parameter from NewApplication function call
database/gorm/logger.go Added environment-based logging level logic using env.IsArtisan()
support/env/env.go Added new IsArtisan() function to detect Artisan environment

Sequence Diagram

sequenceDiagram
    participant App as Application
    participant Env as Environment
    participant Args as Command Line Args

    App->>Env: Check IsArtisan()
    Env->>Args: Iterate through os.Args
    Args-->>Env: Return Artisan status
    Env-->>App: Set application mode
Loading

Possibly related PRs


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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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

codecov bot commented Dec 31, 2024

Codecov Report

Attention: Patch coverage is 41.66667% with 7 lines in your changes missing coverage. Please review.

Project coverage is 69.73%. Comparing base (a8c5084) to head (5a56265).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
database/gorm/logger.go 0.00% 2 Missing and 1 partial ⚠️
support/env/env.go 50.00% 2 Missing and 1 partial ⚠️
console/service_provider.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #800      +/-   ##
==========================================
- Coverage   69.78%   69.73%   -0.05%     
==========================================
  Files         218      218              
  Lines       18858    18866       +8     
==========================================
- Hits        13160    13157       -3     
- Misses       4984     4991       +7     
- Partials      714      718       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@hwbrzzl hwbrzzl marked this pull request as ready for review December 31, 2024 02:23
@hwbrzzl hwbrzzl requested a review from a team as a code owner December 31, 2024 02:23
Copy link
Contributor

@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: 1

🧹 Nitpick comments (1)
support/env/env.go (1)

28-28: Add documentation comment for IsArtisan

For consistency with other functions in this file, please add a documentation comment explaining the purpose of IsArtisan.

+// IsArtisan checks if the application is running in Artisan mode.
 func IsArtisan() bool {
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a8c5084 and 5a56265.

📒 Files selected for processing (6)
  • console/application.go (2 hunks)
  • console/application_test.go (1 hunks)
  • console/cli_helper_test.go (1 hunks)
  • console/service_provider.go (1 hunks)
  • database/gorm/logger.go (1 hunks)
  • support/env/env.go (1 hunks)
🧰 Additional context used
🪛 GitHub Check: codecov/patch
support/env/env.go

[warning] 31-32: support/env/env.go#L31-L32
Added lines #L31 - L32 were not covered by tests

console/service_provider.go

[warning] 20-20: console/service_provider.go#L20
Added line #L20 was not covered by tests

database/gorm/logger.go

[warning] 26-27: database/gorm/logger.go#L26-L27
Added lines #L26 - L27 were not covered by tests

🔇 Additional comments (9)
console/cli_helper_test.go (1)

16-16: Good update to match the new function signature.
Removing the boolean parameter from NewApplication aligns with the recent refactor and simplifies the interface.

database/gorm/logger.go (2)

17-17: Importing the env package here is appropriate.
This import enables the logger to rely on the environment check for Artisan mode, helping unify the logic around logging levels.


25-27: Lines lack test coverage.
Forcing the logger to logger.Error under Artisan mode achieves the PR’s objective of minimizing console log noise. However, static analysis indicates that these lines are not covered by tests, which may reduce overall coverage and confidence in this behavior.

Would you like assistance adding a test to ensure these lines are covered?

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 26-27: database/gorm/logger.go#L26-L27
Added lines #L26 - L27 were not covered by tests

console/application.go (3)

11-11: New import of env package is consistent with the design.
Centralizing the Artisan check in the environment logic helps keep the application setup clean.


21-21: Removal of the boolean parameter streamlines the constructor.
This makes the function signature more intuitive, avoiding knowledge duplication about Artisan mode.


32-32: Setting isArtisan via env.IsArtisan() is more maintainable.
Delegating the Artisan detection to the environment layer centralizes configuration and reduces potential inconsistencies.

console/application_test.go (1)

16-16: Consistent change to the NewApplication call.
This mirrors the updated signature that uses env.IsArtisan() instead of a boolean parameter.

console/service_provider.go (2)

20-20: Verify alignment with PR objective

The removal of the boolean parameter seems to be part of a larger change to control log output. Please verify that this change, combined with env.IsArtisan(), properly supports the PR's objective of suppressing logs during command execution.

✅ Verification successful

The removal of the boolean parameter is properly aligned with the PR's objective

The verification shows that the change is well-integrated with the logging control mechanism:

  • The isArtisan field in the Application struct is now automatically set via env.IsArtisan() during initialization
  • This field is used consistently throughout the application to control command execution behavior
  • The removal of the explicit boolean parameter simplifies the API while maintaining the same functionality through environment-based control
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for logging-related code that might be affected
rg -A 3 "log\." "console/"

Length of output: 26


Script:

#!/bin/bash
# Search for logging-related code with broader patterns
rg -A 3 -i "log" "console/"

# Look for env.IsArtisan usage
rg -A 3 "IsArtisan" "console/"

# Check the removed parameter's history
git log -L :NewApplication:console/service_provider.go

# Look at the full content of service_provider.go
cat console/service_provider.go

Length of output: 1599


Script:

#!/bin/bash
# Check the application.go file for logging control logic
cat console/application.go

# Look for any other files that might contain logging control
rg -A 3 "isArtisan" .

Length of output: 6094

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 20-20: console/service_provider.go#L20
Added line #L20 was not covered by tests


20-20: Add test coverage for the updated NewApplication call

The modified NewApplication call isn't covered by tests. Please add test cases to verify the behavior with the new signature.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 20-20: console/service_provider.go#L20
Added line #L20 was not covered by tests

support/env/env.go Show resolved Hide resolved
@hwbrzzl hwbrzzl merged commit b202f13 into master Dec 31, 2024
10 of 12 checks passed
@hwbrzzl hwbrzzl deleted the bowen/optimize-command-log1 branch December 31, 2024 03:07
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.

1 participant