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

improve log (#554) #657

Merged
merged 2 commits into from
Feb 9, 2025
Merged

improve log (#554) #657

merged 2 commits into from
Feb 9, 2025

Conversation

lidaobing
Copy link
Member

@lidaobing lidaobing commented Feb 9, 2025

/close #554

Summary by Sourcery

Improve logging format. Use pthread instead of std::thread to get thread name. Simplify the log level output to a single character. Shorten the file name in the log output. Change the timestamp format to only include time and milliseconds.

@lidaobing lidaobing linked an issue Feb 9, 2025 that may be closed by this pull request
Copy link

sourcery-ai bot commented Feb 9, 2025

Reviewer's Guide by Sourcery

This PR improves the logging mechanism by modifying how logs are formatted and generated. The implementation replaces C++ thread identification with pthread functions, changes log level representation from strings to single characters, and adjusts both timestamp and filename formatting in log outputs.

No diagrams generated as the changes look simple and do not need a visual representation.

File-Level Changes

Change Details Files
Updated thread identification method
  • Replaced C++ this_thread::get_id() with pthread_self()
  • Added inclusion of <pthread.h> for accessing pthread functions
src/iptux-utils/output.cpp
Modified log level representation
  • Changed the log level function from returning strings to single character codes
  • Mapped log level values (DEBUG, INFO, MESSAGE, WARNING, ERROR, default) to 'D', 'I', 'M', 'W', 'E', and 'U' respectively
src/iptux-utils/output.cpp
Adjusted timestamp format in logs
  • Updated timestamp formatting to exclude the date, showing only hour, minute, and second
  • Changed the strftime format string from '%Y-%m-%d %H:%M:%S' to '%H:%M:%S'
src/iptux-utils/output.cpp
Refactored filename extraction for logging
  • Modified the logic in pretty_fname to use the last occurrence of '/' instead of '/src/'
  • Updated the substring offset from +5 to +1 for extracting the filename
src/iptux-utils/output.cpp
Updated logging format output
  • Adjusted the fprintf format string to accommodate the new log level single character and thread id formatting
  • Removed the inclusion of and added <unistd.h> for system functions
src/iptux-utils/output.cpp

Assessment against linked issues

Issue Objective Addressed Explanation
#554 Remove date from timestamp and add microseconds
#554 Shorten thread identifier to max 4 chars The PR uses the full thread ID from pthread_self(), which is not shortened to 4 characters
#554 Reduce log level from full word to single character
#554 Remove full path from log message, keep only filename and align

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 @lidaobing - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider verifying that using pthread_self() instead of std::this_thread::get_id() produces an easily readable thread identifier on all target platforms.
  • Review whether representing log levels with a single character provides enough clarity for future debugging.
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.

Copy link

github-actions bot commented Feb 9, 2025

Test Results

66 tests  ±0   66 ✅ ±0   2s ⏱️ ±0s
32 suites ±0    0 💤 ±0 
 1 files   ±0    0 ❌ ±0 

Results for commit 8266485. ± Comparison against base commit ec45ec3.

Copy link

codecov bot commented Feb 9, 2025

Codecov Report

Attention: Patch coverage is 69.23077% with 4 lines in your changes missing coverage. Please review.

Project coverage is 52.47%. Comparing base (ec45ec3) to head (8266485).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
src/iptux-utils/output.cpp 69.23% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #657      +/-   ##
==========================================
- Coverage   52.48%   52.47%   -0.02%     
==========================================
  Files          64       64              
  Lines        8558     8558              
==========================================
- Hits         4492     4491       -1     
- Misses       4066     4067       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@lidaobing lidaobing merged commit afc074a into master Feb 9, 2025
16 of 19 checks passed
@lidaobing lidaobing deleted the 554-improve-log branch February 9, 2025 16:44
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.

improve log
1 participant