SkuldNorniern / fluere

Fluere is a powerful and versatile tool designed for network monitoring and analysis. It is capable of capturing network packets in pcap format and converting them into NetFlow data, providing a comprehensive view of network traffic. It also Provides Terminal User Interface.
Apache License 2.0
29 stars 3 forks source link

Sweep: modify `log.rs` to support logging in `.log` file #31

Closed SkuldNorniern closed 10 months ago

SkuldNorniern commented 10 months ago

Details

change the log.rs file to create a proper log file each run with the proper log level handling and on the commit message title, follow the conventional commit rule for linux save the log at /var/log/fluere/, and on windows at the installation dir while not using external crate on the OS target related part, use #[cfg(target_os = "~")] the os need to cover is windows, linux, macos, bsd

Checklist - [X] `src/utils/log.rs` > • Replace the `new()` function in the `Log` struct to create a log file instead of connecting to the syslog. Use the `std::fs::File::create()` function to create the log file. > • Use the `#[cfg(target_os = "~")]` attribute to conditionally compile code based on the target OS. Create the log file at `/var/log/fluere/` for Linux, at the installation directory for Windows, and at the appropriate directories for MacOS and BSD. > • Modify the `log()` function in the `Log` struct to handle different log levels. Use a match statement to handle different log levels and write the appropriate log messages to the log file. > • Use the `std::io::Write` trait's `write()` function to write log messages to the log file. Make sure to handle any errors that may occur during file IO.
sweep-ai[bot] commented 10 months ago

Here's the PR! https://github.com/SkuldNorniern/fluere/pull/46.

⚡ Sweep Free Trial: I used GPT-3.5 to create this ticket. You have 3 GPT-4 tickets left for the month and 0 for the day. For more GPT-4 tickets, visit our payment portal. To retrigger Sweep, edit the issue.


Step 1: 🔍 Code Search

I found the following snippets in your repository. I will now analyze these snippets and come up with a plan.

Some code snippets I looked at (click to expand). If some file is missing from here, you can mention the path in the ticket description. https://github.com/SkuldNorniern/fluere/blob/3e103d6cf85f6a70261d67adec92efacb7c80bd2/src/utils/log.rs#L1-L13 https://github.com/SkuldNorniern/fluere/blob/3e103d6cf85f6a70261d67adec92efacb7c80bd2/src/main.rs#L1-L51 https://github.com/SkuldNorniern/fluere/blob/3e103d6cf85f6a70261d67adec92efacb7c80bd2/Cargo.toml#L1-L59 https://github.com/SkuldNorniern/fluere/blob/3e103d6cf85f6a70261d67adec92efacb7c80bd2/src/plugin/manager.rs#L1-L22 https://github.com/SkuldNorniern/fluere/blob/3e103d6cf85f6a70261d67adec92efacb7c80bd2/src/net/online_fluereflow.rs#L1-L111

Step 2: 🧐 Snippet Analysis

From looking through the relevant snippets, I decided to make the following modifications:

File Path Proposed Changes
src/utils/log.rs Modify src/utils/log.rs with contents:
• Replace the new() function in the Log struct to create a log file instead of connecting to the syslog. Use the std::fs::File::create() function to create the log file.
• Use the #[cfg(target_os = "~")] attribute to conditionally compile code based on the target OS. Create the log file at /var/log/fluere/ for Linux, at the installation directory for Windows, and at the appropriate directories for MacOS and BSD.
• Modify the log() function in the Log struct to handle different log levels. Use a match statement to handle different log levels and write the appropriate log messages to the log file.
• Use the std::io::Write trait's write() function to write log messages to the log file. Make sure to handle any errors that may occur during file IO.

Step 3: 📝 Planning

I have created a plan for writing the pull request. I am now working my plan and coding the required changes to address this issue. Here is the planned pull request:

Modify log.rs to support logging in .log file sweep/logging-support

Description

This PR modifies the log.rs file to support logging to a .log file instead of the syslog. It also implements proper log level handling and follows the conventional commit rule for the commit message title. The changes are made without using any external crate.

Summary

  • Modified the new() function in the Log struct to create a log file using the standard library's std::fs::File::create() function.
  • Conditionally compiled code based on the target OS using the #[cfg(target_os = "~")] attribute. The log file is created at /var/log/fluere/ for Linux, at the installation directory for Windows, and at the appropriate directories for MacOS and BSD.
  • Modified the log() function in the Log struct to handle different log levels. Implemented a match statement to handle different log levels and write the appropriate log messages to the log file.
  • Used the std::io::Write trait's write() function to write log messages to the log file. Handled any errors that may occur during file IO.

Please review and merge this PR. Thank you!


Step 4: ⌨️ Coding

File Instructions Progress
src/utils/log.rs Modify src/utils/log.rs with contents:
• Replace the new() function in the Log struct to create a log file instead of connecting to the syslog. Use the std::fs::File::create() function to create the log file.
• Use the #[cfg(target_os = "~")] attribute to conditionally compile code based on the target OS. Create the log file at /var/log/fluere/ for Linux, at the installation directory for Windows, and at the appropriate directories for MacOS and BSD.
• Modify the log() function in the Log struct to handle different log levels. Use a match statement to handle different log levels and write the appropriate log messages to the log file.
• Use the std::io::Write trait's write() function to write log messages to the log file. Make sure to handle any errors that may occur during file IO.
✅ Commit b86e5ad I have finished coding the issue. I am now reviewing it for completeness.

Step 5: 🔁 Code Review

Here are my self-reviews of my changes at sweep/logging-support.

Here is the 1st review

No changes required. The modifications made in src/utils/log.rs are in line with the issue's request. The implementation of the new file-based logging system appears to be correct and complete. Great job!

I finished incorporating these changes.


🎉 Latest mprovements to Sweep:


💡 To recreate the pull request edit the issue title or description. Join Our Discord