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

fix dev mode logging bug #3972

Merged
merged 2 commits into from
Jan 23, 2025
Merged

Conversation

atterpac
Copy link
Member

@atterpac atterpac commented Dec 30, 2024

The dev mode sets the logger twice, the later time checking it as a string but the options now required a logger.Level type to be passed in. This PR removes the second setting that was resetting to default rather then user defined in options.

# Wails
Version         | v2.9.2
Revision        | 82fd9de3391dc1719f0d60d4aff265ce88e6dbd2
Modified        | true
Package Manager | apt

# System
┌─────────────────────────────────────────────────────────────────────────────────────────┐
| OS           | Ubuntu                                                                   |
| Version      | 24.04                                                                    |
| ID           | ubuntu                                                                   |
| Go Version   | go1.22.2                                                                 |
| Platform     | linux                                                                    |
| Architecture | amd64                                                                    |
| CPU          | 12th Gen Intel(R) Core(TM) i5-1235U                                      |
| GPU          | Alder Lake-UP3 GT2 [Iris Xe Graphics] (Intel Corporation) - Driver: i915 |
| Memory       | 7GB                                                                      |
└─────────────────────────────────────────────────────────────────────────────────────────┘

# Dependencies
┌─────────────────────────────────────────────────────────────────────┐
| Dependency | Package Name          | Status    | Version            |
| *docker    | docker.io             | Installed | 27.3.1             |
| gcc        | build-essential       | Installed | 12.10ubuntu1       |
| libgtk-3   | libgtk-3-dev          | Installed | 3.24.41-4ubuntu1.2 |
| libwebkit  | libwebkit2gtk-4.0-dev | Available | 2.20.1-1           |
| npm        | npm                   | Installed | 10.5.1             |
| *nsis      | nsis                  | Available | 3.09-4ubuntu1      |
| pkg-config | pkg-config            | Installed | 1.8.1-2build1      |
└────────────────────── * - Optional Dependency ──────────────────────┘

Summary by CodeRabbit

  • Documentation

    • Updated changelog with new feature for setting window class name on Windows
    • Removed outdated reference regarding default module name in go.mod
    • Updated Mac App Store guide to support application names containing spaces
  • Bug Fixes

    • Resolved development mode logging configuration
    • Fixed cross-compilation and native webview2loader issues
    • Corrected macOS menu example problems
  • New Features

    • Introduced a method for converting log levels to string representations in the logger package.

Copy link
Contributor

coderabbitai bot commented Dec 30, 2024

Warning

Rate limit exceeded

@leaanthony has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 16 minutes and 11 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 5175127 and 8faa4ea.

📒 Files selected for processing (1)
  • website/src/pages/changelog.mdx (1 hunks)

Walkthrough

The pull request modifies the log level handling in the CreateApp function within v2/internal/app/app_dev.go, refining how the log level is set based on the environment variable. The changes ensure that the log level is only overridden when explicitly specified and differs from the default. Additionally, the changelog.mdx file has been updated to reflect new features, bug fixes, and clarifications in the documentation, enhancing the overall project clarity.

Changes

File Change Summary
v2/internal/app/app_dev.go Updated CreateApp to refine log level handling: initialized loglevelFlag with string representation, modified log level setting logic.
website/src/pages/changelog.mdx Updated documentation: added feature for setting window class name on Windows, fixed dev mode logging bug, and clarified existing entries.
v2/pkg/logger/logger.go Added String() method to LogLevel type for string representation of log levels.

Possibly related PRs

Suggested labels

awaiting feedback

Suggested reviewers

  • leaanthony

Poem

🐰 In the code where the log levels play,
A rabbit hops in, brightening the way.
With flags and strings, we tidy the flow,
Simplifying paths, watch the logging glow!
New features sprout, as bugs fade away,
Hopping along, we celebrate today! 🎉


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.

@atterpac atterpac marked this pull request as ready for review December 30, 2024 05:00
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: 0

🧹 Nitpick comments (1)
website/src/pages/changelog.mdx (1)

24-24: Improve bug fix description

The bug fix entry "Fixed dev mode logging bug by @attperac in #3972" would benefit from more descriptive details about what was fixed.

-Fixed dev mode logging bug by @attperac in [#3972](https://wailsapp/wails/pull/3972)
+Fixed incorrect logger configuration in dev mode where logger was being set twice, causing user-defined options to be reverted by @attperac in [#3972](https://wailsapp/wails/pull/3972)
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 82fd9de and d66d074.

📒 Files selected for processing (2)
  • v2/internal/app/app_dev.go (0 hunks)
  • website/src/pages/changelog.mdx (1 hunks)
💤 Files with no reviewable changes (1)
  • v2/internal/app/app_dev.go
🔇 Additional comments (1)
website/src/pages/changelog.mdx (1)

Line range hint 1-24: LGTM! Version entry follows changelog format

The latest version entry follows the established changelog format with clear sections for Added, Fixed, Changed etc. The formatting is consistent with previous entries.

🧰 Tools
🪛 LanguageTool

[duplication] ~23-~23: Possible typo: you repeated a word
Context: ...app/wails/pull/3828) by @APshenkin ### Fixed - Fixed dev mode logging bug by @attperac in [#...

(ENGLISH_WORD_REPEAT_RULE)

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)
v2/internal/app/app_dev.go (1)

Line range hint 52-57: Consider explicit error handling for invalid log levels

The code silently accepts any string value for the log level. Consider adding validation to ensure only valid log levels are accepted (Trace, Debug, Info, Warning, Error).

Example validation:

if loglevelFlag != nil {
    loglevel = *loglevelFlag
+   validLevels := map[string]bool{"trace": true, "debug": true, "info": true, "warning": true, "error": true}
+   if _, valid := validLevels[strings.ToLower(loglevel)]; !valid {
+       myLogger.Warning("Invalid log level '%s', defaulting to 'debug'", loglevel)
+       loglevel = "debug"
+   }
    logger.SetLogLevel(loglevel)
}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between d66d074 and bfb292e.

📒 Files selected for processing (2)
  • v2/internal/app/app_dev.go (1 hunks)
  • website/src/pages/changelog.mdx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • website/src/pages/changelog.mdx
🔇 Additional comments (1)
v2/internal/app/app_dev.go (1)

94-97: LGTM! The changes align with the PR objectives

The removal of the second logger setting and the pkglogger dependency simplifies the code while maintaining the desired behavior in dev mode. The logger is properly initialized and configured before any logging calls.

@@ -93,6 +92,7 @@ func CreateApp(appoptions *options.App) (*App, error) {
}
if loglevelFlag != nil {
loglevel = *loglevelFlag
logger.SetLogLevel(loglevel)
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

SetLogLevel expects LogLevel type, not string

The verification reveals a type mismatch in the logger configuration:

  • LogLevel is defined as type LogLevel uint8 in the logger package
  • The code is passing loglevel string directly to SetLogLevel without conversion
  • Previously removed StringToLogLevel function was necessary for converting CLI string input to proper LogLevel type

This needs to be fixed by:

  • Restoring the string-to-LogLevel conversion before calling SetLogLevel
  • Using logger.StringToLogLevel(loglevel) to convert the CLI input
🔗 Analysis chain

Verify logger.SetLogLevel type expectations

The removal of pkglogger.StringToLogLevel conversion means we're passing a raw string to SetLogLevel. We should verify that SetLogLevel can handle string values correctly.

Let's check the logger package implementation:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check the SetLogLevel implementation to ensure it can handle string values
ast-grep --pattern 'func SetLogLevel($param) {
  $$$
}'

# Also check for any string to level conversion utilities
rg -A 5 'StringToLogLevel|ParseLogLevel'

Length of output: 443


Script:

#!/bin/bash
# Let's check the SetLogLevel method signature and implementation
ast-grep --pattern 'func ($$$) SetLogLevel($param) {
  $$$
}'

# Also check the type definition of LogLevel
rg -A 3 'type LogLevel'

# Let's also check the actual usage in app_dev.go
rg -B 5 -A 5 'SetLogLevel' v2/internal/app/app_dev.go

Length of output: 1150

@atterpac atterpac marked this pull request as draft December 30, 2024 05:23
changelog.md

retain env support

actually fix the issue
@atterpac atterpac marked this pull request as ready for review December 30, 2024 05:32
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: 0

🧹 Nitpick comments (2)
v2/pkg/logger/logger.go (1)

44-60: Consider providing a more explicit fallback value or error for unrecognized log levels.

Currently, unrecognized log levels default to "debug":

default:
    return "debug"

While this is functional, it may mask configuration errors. As a good-to-have improvement, consider returning an error or a dedicated placeholder like "unknown" to make debugging potential misconfigurations simpler.

website/src/pages/changelog.mdx (1)

24-24: Fix broken link for PR reference.

The link for PR #3972 is missing github.com in the URL. Consider applying the following change:

- Fixed dev mode logging bug by @attperac in [#3972](https://wailsapp/wails/pull/3972)
+ Fixed dev mode logging bug by @attperac in [#3972](https://github.com/wailsapp/wails/pull/3972)
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between bfb292e and 5175127.

📒 Files selected for processing (3)
  • v2/internal/app/app_dev.go (2 hunks)
  • v2/pkg/logger/logger.go (1 hunks)
  • website/src/pages/changelog.mdx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • v2/internal/app/app_dev.go

@leaanthony leaanthony enabled auto-merge (squash) January 23, 2025 11:11
@leaanthony leaanthony merged commit d824318 into wailsapp:master Jan 23, 2025
5 of 6 checks passed
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.

2 participants