Skip to content

Conversation

@davidp57
Copy link
Contributor

@davidp57 davidp57 commented Mar 30, 2025

  • added pluggable logging system
  • moved vec3check higher in the code (else it's not found by one of the callers - sorry for triggering this bug)

Usage
To use the logging system, simply pass a string template (as you would use for string.format) as the first parameter, the parameters being the values to fill in the template.
The parameters will automatically be checked for null and transformed as a string; if they contain a table, they'll be displayed as a table.

Summary by Sourcery

Introduce a pluggable logging system to replace direct env.info calls with a more flexible and configurable logging mechanism

New Features:

  • Implemented a flexible logging system with configurable log levels
  • Added ability to register custom loggers
  • Introduced log level filtering and formatting

Enhancements:

  • Replaced hardcoded env.info calls with a more structured logging approach
  • Added support for log level tracing, debugging, info, warning, and error
  • Improved log message formatting with function and line number context

Chores:

  • Removed AIEN_debugProcessDetail configuration variable
  • Standardized logging across the entire script

- moved vec3check higher in the code (else it's not found by one of the callers - sorry for triggering this bug)
@sourcery-ai
Copy link

sourcery-ai bot commented Mar 30, 2025

Reviewer's Guide by Sourcery

This pull request introduces a pluggable logging system to the AIEN script, allowing for more flexible and controlled logging of information. It also moves the vec3Check function higher in the code to resolve a bug where it was not found by one of the callers.

Sequence diagram for logging an error

sequenceDiagram
    participant AIEN
    participant Logger
    participant env

    AIEN->>AIEN: AIEN.loggers.get(AIEN.Id):error("Error message", ...)
    AIEN->>Logger: error(text, ...)
    Logger->>Logger: formatText(text, ...)
    Logger->>Logger: splitText(text)
    Logger->>env: env.error(self.name .. '|' .. levelChar .. '|' .. texts[i])
    env-->>AIEN: Logs the error message
Loading

Sequence diagram for logging an info message

sequenceDiagram
    participant AIEN
    participant Logger
    participant env

    AIEN->>AIEN: AIEN.loggers.get(AIEN.Id):info("Info message", ...)
    AIEN->>Logger: info(text, ...)
    Logger->>Logger: formatText(text, ...)
    Logger->>Logger: splitText(text)
    Logger->>env: env.info(self.name .. '|' .. levelChar .. '|' .. texts[i])
    env-->>AIEN: Logs the info message
Loading

Class diagram for AIEN.Logger

classDiagram
    class AIEN.Logger {
        -name: string
        -level: number
        --
        +new(name: string, level: string|number): AIEN.Logger
        +setName(value: string): self
        +getName(): string
        +setLevel(value: string|number, force: boolean): self
        +getLevel(): number
        +error(text: string, ...)
        +warn(text: string, ...)
        +info(text: string, ...)
        +debug(text: string, ...)
        +trace(text: string, ...)
        +wouldLogWarn(): boolean
        +wouldLogInfo(): boolean
        +wouldLogDebug(): boolean
        +wouldLogTrace(): boolean
        +splitText(text: string): string[]
        +formatText(text: string, ...): string
    }
    note for AIEN.Logger "Represents a logger instance with configurable level and name."
Loading

File-Level Changes

Change Details Files
Introduced a pluggable logging system.
  • Added a new AIEN.Logger object with methods for setting log level, formatting text, and printing logs.
  • Added a new AIEN.loggers object to manage multiple loggers.
  • Replaced env.info, env.warning, and env.error calls with calls to the new logging system.
  • Added a new AIEN.LogLevel config variable to control the logging level.
  • Added a new AIEN.p function to handle nil values and tables.
  • Added a new AIEN.config.AIEN_debugProcessDetail config variable to control the logging level.
AIEN.lua
Moved vec3Check function higher in the code.
  • Moved the vec3Check function definition before its usage in other functions.
AIEN.lua

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @davidp57 - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider using a more structured configuration, such as a table, instead of global variables for log levels.
  • The AIEN.p function has a recursion limit, but it might be better to avoid recursion altogether for performance reasons.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@davidp57
Copy link
Contributor Author

Isn't Sourcery a blast?

@Chromium18
Copy link
Owner

Yes it is, but I can't change the logging system, I'll try to review with the bugfix only :)

@Chromium18 Chromium18 self-assigned this Mar 31, 2025
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