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

Created logging functions #9

Merged
merged 5 commits into from
May 27, 2024
Merged

Created logging functions #9

merged 5 commits into from
May 27, 2024

Conversation

Bullrich
Copy link
Owner

@Bullrich Bullrich commented May 27, 2024

Created many methods for logging

  • debug_log
  • info
  • warn_log
  • error_log
  • notice_log
  • is_debug

Summary by CodeRabbit

  • New Features

    • Introduced logging methods for debug, info, warning, error, and notice messages.
    • Added functionality to check if the code is running on a debug runner.
  • Documentation

    • Updated documentation link in the project configuration.
    • Enhanced README with usage examples, installation instructions, and a GitHub Actions badge.
  • Refactor

    • Updated error handling for the set_output function in the core module.

@Bullrich Bullrich self-assigned this May 27, 2024
Copy link

coderabbitai bot commented May 27, 2024

Walkthrough

The project underwent several updates, including the removal of the [lib] section from Cargo.toml, the addition of a documentation link, and the introduction of a new logger module. Changes also include enhanced error handling in the set_output function and updates to the README for better clarity and usage examples.

Changes

Files Change Summary
Cargo.toml Removed [lib] section with doctest setting; added documentation key with a link.
README.md Updated documentation link, marked logging methods as implemented, added GitHub Actions badge.
src/core.rs Updated set_output function to include error handling using panic.
src/lib.rs Added a new logger module.
src/logger.rs Introduced logging functions: debug_log, info, warn_log, error_log, notice_log, is_debug.

In code we trust, as we refine,
With logs and links, our work aligns.
Outputs set, errors tamed,
In Rust we see our goals proclaimed.
A badge of pride, in actions' light,
Our project grows, both day and night.


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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.

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 as 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 full the 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 help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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: 1

Outside diff range and nitpick comments (1)
src/logger.rs (1)

22-27: Ensure consistent error messages in logging functions.

The error message in info function mentions "debug message" which might be confusing. Consider updating it to "info message":

.write_all((msg.to_owned() + EOL).as_bytes())
.expect("Failed to write info message")
Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 080cc5c and 767cb7e.
Files selected for processing (5)
  • Cargo.toml (1 hunks)
  • README.md (3 hunks)
  • src/core.rs (1 hunks)
  • src/lib.rs (1 hunks)
  • src/logger.rs (1 hunks)
Files skipped from review due to trivial changes (3)
  • Cargo.toml
  • README.md
  • src/lib.rs
Additional comments not posted (1)
src/logger.rs (1)

77-89: Review the default behavior of is_debug.

The function is_debug defaults to true when the RUNNER_DEBUG environment variable is not set. This could lead to unexpected behavior in production environments where debug logging is typically disabled. Verify if this behavior aligns with the intended use cases:

Verification successful

The function is_debug defaults to true when the RUNNER_DEBUG environment variable is not set. Based on the comprehensive search results, is_debug is only used in a test assertion and not elsewhere in the codebase. Therefore, the current usage does not pose any issues. However, it is recommended to ensure that the default behavior is well-documented to avoid any confusion or unintended consequences in future development.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Check the usage of `is_debug` across the codebase to ensure it's used appropriately.

# Test: Search for the function usage. Expect: Proper checks before using this function.
rg --type rust $'logger::is_debug()'

Length of output: 84



Script:

#!/bin/bash
# Description: Perform a comprehensive search for all occurrences of `is_debug` in the codebase.

# Search for direct calls to `is_debug`
rg --type rust 'is_debug()'

# Search for any indirect usages by looking for references to the `logger` module
rg --type rust 'logger'

Length of output: 805

Comment on lines +30 to +33
/// use actions_github::core;
/// if let Err(err) = core::set_output("name", "value") {
/// panic!("{:#?}", err);
/// }
Copy link

Choose a reason for hiding this comment

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

Consider revising the error handling strategy in set_output.

Using panic for error handling in a library can lead to abrupt termination of the entire application using this library, which might not be desirable. Consider returning the error to the caller to handle it more gracefully:

pub fn set_output(name: &str, value: &str) -> Result<(), ActionsError> {
    if env::var("GITHUB_OUTPUT").is_ok() {
        return match prepare_key_value_message(name, value) {
            Ok(key_value_message) => match issue_file_command("OUTPUT", key_value_message) {
                Ok(_) => Ok(()),
                Err(err) => Err(ActionsError::Output(err)),
            },
            Err(err) => Err(ActionsError::Output(err)),
        };
    }

    io::stdout()
        .write_all(EOL.as_bytes())
        .expect("Failed to write EOL");
    issue_old_command("set-output", name, value);
    Err(ActionsError::Output("Failed to set output".to_string()))
}

@Bullrich Bullrich merged commit 686bc13 into main May 27, 2024
6 checks passed
@Bullrich Bullrich deleted the logger branch May 27, 2024 12:49
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: 1

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 767cb7e and cef79a1.
Files selected for processing (3)
  • README.md (3 hunks)
  • src/core.rs (2 hunks)
  • src/logger.rs (1 hunks)
Files skipped from review as they are similar to previous changes (2)
  • src/core.rs
  • src/logger.rs
Additional Context Used
LanguageTool (1)
README.md (1)

Near line 23: A determiner appears to be missing. Consider inserting it.
Context: ...stallation cargo add actions-github Latest version available is [![latest version]...
Rule ID: AI_EN_LECTOR_MISSING_DETERMINER

Additional comments not posted (2)
README.md (2)

18-18: Update to reflect the implementation of logging methods.

This line confirms the completion of logging methods as part of the library's features.


33-33: Ensure proper usage of the new logging methods.

The code snippets correctly demonstrate the usage of the newly implemented logging methods (info, debug) and the set_output function. This aligns well with the PR's objectives to introduce logging functionalities.

Also applies to: 36-36, 61-61


## Installation

`cargo add actions-github`

Latest version available is [![latest version](https://img.shields.io/crates/v/actions-github)](https://crates.io/crates/actions-github)
Copy link

Choose a reason for hiding this comment

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

Clarify the version information.

Consider adding a determiner before "Latest version available" for grammatical correctness. For example:

- Latest version available is [![latest version](https://img.shields.io/crates/v/actions-github)](https://crates.io/crates/actions-github)
+ The latest version available is [![latest version](https://img.shields.io/crates/v/actions-github)](https://crates.io/crates/actions-github)

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.

Suggested change
Latest version available is [![latest version](https://img.shields.io/crates/v/actions-github)](https://crates.io/crates/actions-github)
The latest version available is [![latest version](https://img.shields.io/crates/v/actions-github)](https://crates.io/crates/actions-github)

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

Successfully merging this pull request may close these issues.

1 participant