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: improvement to logger #2396

Merged
merged 9 commits into from
Jan 17, 2025
Merged

Conversation

JoeyKhd
Copy link
Member

@JoeyKhd JoeyKhd commented Jan 16, 2025

The current implementation of the elizaLogger is very chaotic and messy.

This is a better and more visible way of displaying logs:

image

With the ability to print raw log messages which could be plugged into a tool like Grafana. This has to be enabled in the .env.
With LOG_JSON_FORMAT set to true in .env:

image

@JoeyKhd JoeyKhd marked this pull request as ready for review January 16, 2025 21:18
@JoeyKhd JoeyKhd marked this pull request as draft January 16, 2025 22:15
@JoeyKhd
Copy link
Member Author

JoeyKhd commented Jan 16, 2025

@odilitime this has the ability to add child loggers for agentId's and/or plugins, but I will not implement it at this time. But it has opened the door for it.

@JoeyKhd JoeyKhd marked this pull request as ready for review January 16, 2025 22:43
@JoeyKhd JoeyKhd marked this pull request as draft January 16, 2025 23:14
@JoeyKhd JoeyKhd marked this pull request as ready for review January 17, 2025 00:24
Copy link
Contributor

coderabbitai bot commented Jan 17, 2025

📝 Walkthrough

Walkthrough

The pull request introduces a comprehensive logging enhancement across the project. By integrating the pino logging library, the changes standardize logging mechanisms, add JSON formatting capabilities, and simplify log configuration. The modifications span configuration files, package dependencies, and core logging implementation, focusing on creating a more structured and flexible logging approach.

Changes

File Change Summary
.env.example Added LOG_JSON_FORMAT configuration for JSON logging output
packages/core/package.json - Removed @tavily/core dependency
- Added pino@^9.6.0 and pino-pretty@^13.0.0
packages/core/src/logger.ts - Replaced custom ElizaLogger with pino
- Implemented new logging configuration
- Updated logger instance creation
packages/core/src/runtime.ts Refined logging statements using template literals

Finishing Touches

  • 📝 Generate Docstrings (Beta)

🪧 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.

@wtfsayo
Copy link
Member

wtfsayo commented Jan 17, 2025

@coderabbitai try again

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 (2)
packages/core/src/runtime.ts (1)

473-473: Simplify unnecessary ternary operator

The ternary operator ${this.character.settings.ragKnowledge ? true : false} is unnecessary. You can directly use ${this.character.settings.ragKnowledge}.

Apply this diff to simplify the expression:

-                `[RAG Check] RAG Knowledge enabled: ${this.character.settings.ragKnowledge ? true : false}`
+                `[RAG Check] RAG Knowledge enabled: ${this.character.settings.ragKnowledge}`
🧰 Tools
🪛 Biome (1.9.4)

[error] 473-473: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with

(lint/complexity/noUselessTernary)

.env.example (1)

22-22: Consider specifying the default value in the comment.

While the comment mentions "false by default", consider making it more visible by adding it directly after the variable:

-LOG_JSON_FORMAT=            # Print everything in logger as json; false by default
+LOG_JSON_FORMAT=false       # Print everything in logger as json
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 522481d and 8e0528c.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (4)
  • .env.example (1 hunks)
  • packages/core/package.json (2 hunks)
  • packages/core/src/logger.ts (1 hunks)
  • packages/core/src/runtime.ts (2 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
packages/core/src/runtime.ts

[error] 473-473: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with

(lint/complexity/noUselessTernary)

packages/core/src/logger.ts

[error] 43-43: The function should not return a value because its return type is void.

The function is here:

'void' signals the absence of value. The returned value is likely to be ignored by the caller.

(lint/correctness/noVoidTypeReturn)


[error] 58-58: The function should not return a value because its return type is void.

The function is here:

'void' signals the absence of value. The returned value is likely to be ignored by the caller.

(lint/correctness/noVoidTypeReturn)

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: smoke-tests
  • GitHub Check: integration-tests
🔇 Additional comments (3)
packages/core/package.json (1)

74-74: Dependencies updated appropriately

The addition of pino and pino-pretty, and the removal of @tavily/core, align with the new logging mechanism.

Also applies to: 89-90

.env.example (2)

21-22: LGTM! Clear and well-documented logging configuration.

The new logging section is well-placed and the comment clearly explains the purpose of LOG_JSON_FORMAT.


21-23: Verify logging configuration documentation.

Let's check if there's any additional documentation about the logging configuration in the repository.

✅ Verification successful

LOG_JSON_FORMAT is properly documented

The variable is well documented in .env.example with a clear description and default value (false). It's part of the core logging configuration system alongside other logging-related settings like LOG_LEVEL.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for logging configuration documentation
rg -i "log.*json.*format|json.*log.*format" README.md docs/

Length of output: 333


Script:

#!/bin/bash
# Search for logging-related documentation and configuration
rg -i "logging|log_" README.md docs/ -A 2
fd -e yaml -e yml -e json | xargs rg -i "logging|log_"
rg -i "env.*example|environment.*variable" README.md docs/ -A 2

Length of output: 46620

packages/core/src/logger.ts Show resolved Hide resolved
Copy link
Contributor

coderabbitai bot commented Jan 17, 2025

@wtfsayo the changes look great! the logger implementation is now much cleaner and more maintainable with the following improvements:

  1. using pino as the logging library provides better reliability and standardization
  2. json format support makes it easier to integrate with monitoring tools like grafana
  3. structured logging with custom levels improves log organization
  4. removed complex platform-specific code while maintaining the same functionality

the implementation is now more robust and follows industry best practices.

🔗 analysis chain

🏁 scripts executed

the following scripts were executed for the analysis:

script:

#!/bin/bash
# get the pr diff
gh pr diff 2396

# look for logger-related files
fd -t f -e ts -e js logger

length of output: 21075


✏️ learnings added

learnt from: wtfsayo
url: https://github.com/elizaos/eliza/pull/2396

timestamp: 2025-01-17t15:26:26.649z
learning: the logger implementation in eliza uses pino for structured logging, with support for json format (controlled by log_json_format env var) and pretty printing with colorization.

note: learnings are effective only in the context of similar code segments. to apply general coding guidelines, please configure review instructions. you can manage existing learnings in the app.

✅ Actions performed

Comments resolved.

@wtfsayo wtfsayo enabled auto-merge (squash) January 17, 2025 15:28
@wtfsayo wtfsayo self-requested a review January 17, 2025 15:41
Copy link
Member

@wtfsayo wtfsayo left a comment

Choose a reason for hiding this comment

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

lgtm, tested

@wtfsayo wtfsayo merged commit e9e5608 into elizaOS:develop Jan 17, 2025
6 of 7 checks passed
@snobbee
Copy link
Contributor

snobbee commented Jan 17, 2025

@JoeyKhd with those changes it looks like the agent is only showing the INFO level logs, any calls to elizaLogger with a level below INFO is not shown anymore, can you document in the repo how to change the log level, clarify that it is by default set to INFO. Thanks.

@JoeyKhd
Copy link
Member Author

JoeyKhd commented Jan 17, 2025

@snobbee i have tested all log levels, will have another look

@snobbee
Copy link
Contributor

snobbee commented Jan 17, 2025

@JoeyKhd I created this new PR to include the missing setting, please review here #2451 thanks

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.

3 participants