Skip to content

Fixed logs issue while setting up enviroment #3185

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

Closed
wants to merge 1 commit into from

Conversation

harshdev2909
Copy link

@harshdev2909 harshdev2909 commented Feb 9, 2025

Summary by CodeRabbit

  • New Features
    • Enhanced logging management now supports asynchronous updates and configuration persistence.
    • The system automatically checks and creates necessary log directories, ensuring improved stability and a smoother operational experience.

Copy link

coderabbitai bot commented Feb 9, 2025

Walkthrough

The changes enhance the logging setup in two areas. In setup.ts, the fileURLToPath import is added and the dirname constant is defined for improved ES module compatibility. The transactionLogPath function is now asynchronous, returns a Promise, writes updated configuration to the .env file, and uses a recursive option for directory creation. In src/index.ts, a new logs directory check is implemented that creates the directory recursively if it does not exist.

Changes

File(s) Change Summary
setup.ts Added fileURLToPath import; introduced dirname constant; updated transactionLogPath signature to async with Promise return type; writes config to .env and uses mkdirSync with { recursive: true } for log directory creation; updated path resolution for cleanup logic.
src/index.ts Introduced logsDirPath constant; added existence check using fs.existsSync; created logs directory with mkdirSync and { recursive: true } if needed.

Sequence Diagram(s)

sequenceDiagram
    participant Caller as Caller
    participant TLog as transactionLogPath Function
    participant FS as File System
    Caller->>TLog: Call transactionLogPath(logPath)
    TLog->>FS: Create log directory (mkdirSync { recursive: true })
    TLog->>FS: Write updated config to .env
    TLog->>Caller: Return Promise<void>
Loading
sequenceDiagram
    participant Server as Server Startup
    participant FS as File System
    Server->>FS: Check logs directory (existsSync)
    alt Directory does not exist
       Server->>FS: Create logs directory (mkdirSync { recursive: true })
    else Directory exists
       Server->>Server: Continue operation
    end
Loading

Possibly related PRs

Suggested labels

ignore-sensitive-files-pr

Suggested reviewers

  • palisadoes

Poem

I'm a rabbit with a coding thrill,
Hopping through logs with async skill.
Directories grow with a recursive call,
Configs saved right, no step too small.
With whiskers twitching in pure delight,
I celebrate these changes day and night! 🐇

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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.

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

github-actions bot commented Feb 9, 2025

Our Pull Request Approval Process

Thanks for contributing!

Testing Your Code

Remember, your PRs won't be reviewed until these criteria are met:

  1. We don't merge PRs with poor code quality.
    1. Follow coding best practices such that CodeRabbit.ai approves your PR.
  2. We don't merge PRs with failed tests.
    1. When tests fail, click on the Details link to learn more.
    2. Write sufficient tests for your changes (CodeCov Patch Test). Your testing level must be better than the target threshold of the repository
    3. Tests may fail if you edit sensitive files. Ask to add the ignore-sensitive-files-pr label if the edits are necessary.
  3. We cannot merge PRs with conflicting files. These must be fixed.

Our policies make our code better.

Reviewers

Do not assign reviewers. Our Queue Monitors will review your PR and assign them.
When your PR has been assigned reviewers contact them to get your code reviewed and approved via:

  1. comments in this PR or
  2. our slack channel

Reviewing Your Code

Your reviewer(s) will have the following roles:

  1. arbitrators of future discussions with other contributors about the validity of your changes
  2. point of contact for evaluating the validity of your work
  3. person who verifies matching issues by others that should be closed.
  4. person who gives general guidance in fixing your tests

CONTRIBUTING.md

Read our CONTRIBUTING.md file. Most importantly:

  1. PRs with issues not assigned to you will be closed by the reviewer
  2. Fix the first comment in the PR so that each issue listed automatically closes

Other

  1. 🎯 Please be considerate of our volunteers' time. Contacting the person who assigned the reviewers is not advised unless they ask for your input. Do not @ the person who did the assignment otherwise.
  2. Read the CONTRIBUTING.md file make

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Congratulations on making your first PR! 🎊 If you haven't already, check out our Contributing Guidelines and PR Reporting Guidelines to ensure that you are following our guidelines for contributing and creating PR.

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

🔭 Outside diff range comments (1)
src/index.ts (1)

108-109: Remove ESLint disable statement.

The pipeline indicates that ESLint disable statements are not allowed. Consider handling the unused variables properly instead of disabling the lint rule.

Apply this diff to fix the ESLint warning:

-  // eslint-disable-next-line @typescript-eslint/no-unused-vars
-  { schema, context: (_ctx, _msg, _args) => ({ pubsub }) },
+  { schema, context: (ctx, msg, args) => ({ pubsub }) },

If these parameters are truly not needed, you can remove them:

-  // eslint-disable-next-line @typescript-eslint/no-unused-vars
-  { schema, context: (_ctx, _msg, _args) => ({ pubsub }) },
+  { schema, context: () => ({ pubsub }) },
🧹 Nitpick comments (1)
src/index.ts (1)

55-58: Ensure logs directory exists before server start.

The code correctly checks for and creates the logs directory if it doesn't exist. However, this should be moved before the server initialization to ensure the directory exists before any logging operations begin.

Move this block before the server initialization, around line 61:

-    const logsDirPath = path.resolve(dirname, 'logs');
-    if (!fs.existsSync(logsDirPath)) {
-      fs.mkdirSync(logsDirPath, { recursive: true });
-    }
+// Ensure logs directory exists
+const logsDirPath = path.resolve(dirname, 'logs');
+if (!fs.existsSync(logsDirPath)) {
+  fs.mkdirSync(logsDirPath, { recursive: true });
+}
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 466a2a7 and bd3420e.

📒 Files selected for processing (2)
  • setup.ts (1 hunks)
  • src/index.ts (1 hunks)
🧰 Additional context used
🪛 GitHub Actions: PR Workflow
src/index.ts

[error] 1-1: File contains eslint-disable statement. Please remove them and ensure the code adheres to the specified ESLint rules.

setup.ts

[error] 1-1: File is unauthorized to change/delete.

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Analyse Code With CodeQL (typescript)

Comment on lines +142 to +144
import { fileURLToPath } from "url";

const dirname = path.dirname(fileURLToPath(import.meta.url));
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Unauthorized file modification.

This file is marked as unauthorized for changes. The ES module compatibility improvements should be submitted in a separate, authorized PR.

Please:

  1. Revert changes to this file
  2. Create a new PR specifically for ES module compatibility improvements after getting necessary approvals

Comment on lines +146 to 183
async function transactionLogPath(logPath: string | null): Promise<void> {
const config = dotenv.parse(fs.readFileSync(".env"));
config.LOG = "true";

if (!logPath) {
// Check if the logs/transaction.log file exists, if not, create it
const defaultLogPath = path.resolve(__dirname, "logs");
const defaultLogPath = path.resolve(dirname, "logs");
const defaultLogFile = path.join(defaultLogPath, "transaction.log");

if (!fs.existsSync(defaultLogPath)) {
console.log("Creating logs/transaction.log file...");
fs.mkdirSync(defaultLogPath);
fs.mkdirSync(defaultLogPath, { recursive: true });
}

config.LOG_PATH = defaultLogFile;
} else {
// Remove the logs files, if exists
const logsDirPath = path.resolve(__dirname, "logs");
const logsDirPath = path.resolve(dirname, "logs");

if (fs.existsSync(logsDirPath)) {
fs.readdirSync(logsDirPath).forEach((file: string) => {
if (file !== "README.md") {
const curPath = path.join(logsDirPath, file);
fs.unlinkSync(curPath);
fs.unlinkSync(curPath); // Removes all files except "README.md"
}
});
}
config.LOG_PATH = logPath;
}

// Optionally save the updated configuration
fs.writeFileSync(
".env",
Object.entries(config)
.map(([key, value]) => `${key}=${value}`)
.join("\n"),
);
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Unauthorized function modification.

The improvements to transactionLogPath function (async/await, better error handling) should be submitted in a separate, authorized PR.

Please:

  1. Revert changes to this function
  2. Create a new PR for these improvements after getting necessary approvals

@palisadoes
Copy link
Contributor

There isn’t an issue assigned to you for this PR. Please follow the guidelines in our PR_GUIDELINES.md file. We have the procedures in place so that everyone has a fair chance of contributing. I will be closing this pull request. Please follow the procedures and resubmit when ready.

@palisadoes palisadoes closed this Feb 9, 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