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(client): Add a new console class that allow us show extra info passed to log #21170

Merged

Conversation

Tainan404
Copy link
Member

What does this PR do?

This PR adds a env variable to show detailed logs on browser-bunyan, also I had to create a new console stream to proccess this new data based on this issue on browser-bunyan repository 104

OBS: I used a env variable because of some limitation on settings being fetched after the logger be loaded

Closes Issue(s)

#21053

How to test

Change the env variable DETAILED_LOGS to true and look at browser logs

@ramonlsouza ramonlsouza added this to the Release 3.0 milestone Sep 12, 2024
@ramonlsouza ramonlsouza self-requested a review September 13, 2024 19:35
Copy link
Contributor

coderabbitai bot commented Oct 4, 2024

Walkthrough

The changes introduce a new logging mechanism in the bigbluebutton-html5 project. A new class, ConsoleFormattedStream, is added to handle formatted console logging with various logging levels. The logging behavior is modified in the createStreamForTarget function to utilize this new class based on the DETAILED_LOGS environment variable. Additionally, the package.json is updated to include a new dependency for logging levels and to enhance the start script for detailed logging. The Webpack configuration is also adjusted to define the DETAILED_LOGS variable.

Changes

File Change Summary
bigbluebutton-html5/imports/startup/client/logger/consoleStream.ts Added ConsoleFormattedStream class with a write method for formatted logging.
bigbluebutton-html5/imports/startup/client/logger/index.ts Updated createStreamForTarget to conditionally use ConsoleStream or ConsoleFormattedStream based on DETAILED_LOGS.
bigbluebutton-html5/package.json Updated start script to include DETAILED_LOGS=true and added dependency @browser-bunyan/levels.
bigbluebutton-html5/webpack.config.js Introduced detailedLogs constant to manage DETAILED_LOGS environment variable in Webpack configuration.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant LoggerFactory
    participant ConsoleFormattedStream

    Client->>LoggerFactory: Request logger stream
    LoggerFactory->>LoggerFactory: Check process.env.DETAILED_LOGS
    alt DETAILED_LOGS is true
        LoggerFactory->>ConsoleFormattedStream: Use ConsoleFormattedStream
    else DETAILED_LOGS is false
        LoggerFactory->>ConsoleStream: Use ConsoleStream
    end
    LoggerFactory-->>Client: Return selected logger stream
Loading

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between f9c77ca and f067ce6.

📒 Files selected for processing (2)
  • bigbluebutton-html5/imports/startup/client/logger/consoleStream.ts (1 hunks)
  • bigbluebutton-html5/imports/startup/client/logger/index.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • bigbluebutton-html5/imports/startup/client/logger/consoleStream.ts
  • bigbluebutton-html5/imports/startup/client/logger/index.ts

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 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
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: 3

🧹 Outside diff range and nitpick comments (5)
bigbluebutton-html5/webpack.config.js (1)

9-9: LGTM with a minor suggestion.

The addition of the detailedLogs constant aligns well with the PR objectives. It correctly uses the DETAILED_LOGS environment variable to control the logging detail.

Consider using nullish coalescing operator (??) instead of logical OR (||) to handle cases where DETAILED_LOGS might be intentionally set to falsy values like empty string:

const detailedLogs = process.env.DETAILED_LOGS ?? false;

This ensures that only null or undefined values trigger the default false.

bigbluebutton-html5/imports/startup/client/logger/index.ts (2)

41-41: LGTM: Conditional stream selection implemented correctly.

The implementation aligns well with the PR objective of introducing an environment variable to enable detailed logs. The condition correctly checks if DETAILED_LOGS is truthy, using the new ConsoleStream when true and falling back to ConsoleFormattedStream otherwise.

For improved clarity, consider using explicit boolean comparison:

-      Stream = process.env.DETAILED_LOGS ? ConsoleStream : ConsoleFormattedStream;
+      Stream = process.env.DETAILED_LOGS === 'true' ? ConsoleStream : ConsoleFormattedStream;

This change would make it clear that the environment variable is expected to be a string 'true' rather than a boolean.


ConsoleStream Implementation Incomplete

The ConsoleStream class in ./bigbluebutton-html5/imports/startup/client/logger/consoleStream.ts does not implement the expected write method as defined in the verification pattern. This may affect the functionality of toggling detailed logs using the DETAILED_LOGS environment variable.

  • File: ./bigbluebutton-html5/imports/startup/client/logger/consoleStream.ts
  • Issue: Missing or incorrectly implemented write method in ConsoleStream class.

Please review and update the ConsoleStream implementation to ensure it includes the necessary methods for proper logging functionality.

🔗 Analysis chain

Line range hint 1-124: Overall implementation meets PR objectives with room for minor improvements.

The changes successfully implement the desired functionality of using an environment variable (DETAILED_LOGS) to toggle detailed logs. The implementation is correct and aligns well with the PR objectives.

To further improve the code:

  1. Consider using explicit boolean comparison for the DETAILED_LOGS environment variable.
  2. Refactor the switch statement to reduce code duplication.

These minor improvements would enhance code clarity and maintainability without changing the core functionality.

To ensure that the new ConsoleStream is properly implemented and imported, run the following verification script:

This script will help verify the proper implementation and usage of the new ConsoleStream and the DETAILED_LOGS environment variable.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation and import of ConsoleStream

# Test 1: Check if ConsoleStream file exists
fd --type file --extension ts --exec echo "ConsoleStream file found: {}" consoleStream.ts

# Test 2: Verify ConsoleStream implementation
ast-grep --lang typescript --pattern $'class ConsoleStream {
  $$$
  write($_) {
    $$$
  }
  $$$
}' consoleStream.ts

# Test 3: Check usage of DETAILED_LOGS environment variable
rg --type typescript 'process\.env\.DETAILED_LOGS'

Length of output: 45903


Script:

#!/bin/bash
# Description: Enhanced verification of ConsoleStream implementation and DETAILED_LOGS usage

# Test 1: Find all consoleStream.ts files
fd --type file --extension ts --name 'consoleStream.ts' --exec echo "Found ConsoleStream.ts: {}" \;

# Test 2: Verify ConsoleStream implementation in each found file
fd --type file --extension ts --name 'consoleStream.ts' | while read -r file; do
  echo "Checking implementation in $file"
  ast-grep --lang typescript --pattern $'class ConsoleStream {\n  $$$\n  write($_) {\n    $$$\n  }\n  $$$\n}' "$file"
done

# Test 3: Check usage of DETAILED_LOGS environment variable
rg 'process\.env\.DETAILED_LOGS' --glob '*.ts'

Length of output: 1042


Script:

#!/bin/bash
# Description: Corrected verification of ConsoleStream implementation and DETAILED_LOGS usage

# Test 1: Find all consoleStream.ts files
fd --type file --extension ts 'consoleStream.ts' --exec echo "Found ConsoleStream.ts: {}" \;

# Test 2: Verify ConsoleStream implementation in each found file
fd --type file --extension ts 'consoleStream.ts' | while read -r file; do
  echo "Checking implementation in $file"
  ast-grep --lang typescript --pattern 'class ConsoleStream {\n  $$$\n  write($_) {\n    $$$\n  }\n  $$$\n}' "$file"
done

# Test 3: Check usage of DETAILED_LOGS environment variable
rg 'process\.env\.DETAILED_LOGS' -g '*.ts'

Length of output: 967

bigbluebutton-html5/package.json (1)

6-6: LGTM! Consider making the detailed logging configurable.

The addition of DETAILED_LOGS=true to the start script aligns well with the PR objective to enhance logging capabilities during development. This change ensures that detailed logs are available when running the development server.

Consider making this configurable by using a conditional environment variable:

-    "start": "NODE_ENV=development DETAILED_LOGS=true webpack serve --open --config webpack.config.js",
+    "start": "NODE_ENV=development DETAILED_LOGS=${DETAILED_LOGS:-true} webpack serve --open --config webpack.config.js",

This change would allow developers to override the default true value if needed, providing more flexibility.

bigbluebutton-html5/imports/startup/client/logger/consoleStream.ts (1)

45-45: Typo in comment on line 45

The comment contains a typographical error. The word 'spacs' should be corrected to 'spaces' for clarity.

Apply this diff to fix the typo:

- //get level name and pad start with spacs
+ //get level name and pad start with spaces
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 2b3a9b8 and f9c77ca.

⛔ Files ignored due to path filters (1)
  • bigbluebutton-html5/package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (4)
  • bigbluebutton-html5/imports/startup/client/logger/consoleStream.ts (1 hunks)
  • bigbluebutton-html5/imports/startup/client/logger/index.ts (2 hunks)
  • bigbluebutton-html5/package.json (2 hunks)
  • bigbluebutton-html5/webpack.config.js (2 hunks)
🧰 Additional context used
🪛 Biome
bigbluebutton-html5/imports/startup/client/logger/consoleStream.ts

[error] 99-99: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

🔇 Additional comments (4)
bigbluebutton-html5/webpack.config.js (2)

Line range hint 1-146: Overall implementation looks good.

The changes to the webpack configuration file successfully implement the detailed logs feature as described in the PR objectives. The DETAILED_LOGS environment variable is correctly defined and made accessible to the application code.

A few points to consider:

  1. Ensure that the application code is updated to utilize process.env.DETAILED_LOGS for controlling log verbosity.
  2. Update the project documentation to explain how to use the DETAILED_LOGS environment variable.
  3. Consider adding a test case that verifies the behavior of the application with different DETAILED_LOGS values.

Great job on implementing this feature!


42-42: LGTM. Verify the implementation in application code.

The addition of 'process.env.DETAILED_LOGS': detailedLogs, to the webpack.DefinePlugin configuration correctly makes the DETAILED_LOGS environment variable accessible within the application code. This implementation aligns with the PR objectives and follows webpack best practices.

To ensure the DETAILED_LOGS environment variable is being used correctly in the application code, please run the following script:

This script will help verify that the DETAILED_LOGS environment variable is being utilized appropriately in the codebase.

bigbluebutton-html5/imports/startup/client/logger/index.ts (1)

8-8: LGTM: ConsoleStream import added correctly.

The import statement for ConsoleStream is correctly placed and follows the existing import style in the file. This import is necessary for the subsequent usage of ConsoleStream in the createStreamForTarget function.

bigbluebutton-html5/package.json (1)

44-44: LGTM! Verify usage of the new dependency.

The addition of @browser-bunyan/levels aligns with the PR objective to enhance logging capabilities. This package is likely used to define log levels for the browser-bunyan logging framework.

To ensure this dependency is properly utilized, please run the following script to check for its usage in the codebase:

This script will help confirm that the newly added dependency is actually being used in the project.

✅ Verification successful

Verification Successful: Dependency Usage Confirmed

The newly added dependency @browser-bunyan/levels is being utilized in imports/startup/client/logger/consoleStream.ts, ensuring it is properly integrated into the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of @browser-bunyan/levels in the codebase

# Search for import statements or require calls for @browser-bunyan/levels
echo "Searching for usage of @browser-bunyan/levels:"
rg --type js --type ts "from\s+['\"]@browser-bunyan/levels['\"]|require\(['\"]@browser-bunyan/levels['\"]\)"

# If no results are found, it might indicate that the package is not yet used
if [ $? -ne 0 ]; then
    echo "Warning: No usage of @browser-bunyan/levels found. Ensure it's being used in the codebase."
fi

Length of output: 339

Copy link

sonarqubecloud bot commented Oct 4, 2024

@antobinary antobinary changed the title Change: Add a new console class that allow us show extra info passed to log fix(client): Add a new console class that allow us show extra info passed to log Oct 4, 2024
Copy link

github-actions bot commented Oct 4, 2024

Automated tests Summary

All the CI tests have passed!

@ramonlsouza ramonlsouza merged commit fce005d into bigbluebutton:v3.0.x-release Oct 4, 2024
28 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