Skip to content

Add feature to print line number#1804

Closed
pmnoxx wants to merge 2 commits intotokio-rs:masterfrom
pmnoxx:piotr-print-line-number-feature
Closed

Add feature to print line number#1804
pmnoxx wants to merge 2 commits intotokio-rs:masterfrom
pmnoxx:piotr-print-line-number-feature

Conversation

@pmnoxx
Copy link

@pmnoxx pmnoxx commented Dec 26, 2021

Motivation

We have been using tracing for logging. However, one if it's major drawbacks is inability to display line numbers.
When looking at logs I noticed that we spend a huge portion of log to display the target, but the line number is not included,
making the log somewhat useless.

I often use tracing for debugging, and I would prefer to have line numbers written. As a user of log4j. I know how important line numbers are while debugging issues. It allows to quickly jump to the right line number to see the code, which printed the error, rather than having to search for it. Sometimes, it's not possible to uniquely determine which line logged given message, unless the user specifies it.

Solution

Add logging line numbers, for example:

2021-12-26T23:09:29.508100Z  INFO play_ground::anything:6: res=[1, 2, 4, 8, 16, 32]
2021-12-26T23:09:29.508135Z  INFO play_ground::anything:22: send=Err(Os { code: 89, kind: Uncategorized, message: "Destination address required" })

Previously, the message would be:

2021-12-26T23:09:29.508100Z  INFO play_ground::anything: res=[1, 2, 4, 8, 16, 32]
2021-12-26T23:09:29.508135Z  INFO play_ground::anything: send=Err(Os { code: 89, kind: Uncategorized, message: "Destination address required" })

Notes:

  • line_numbers are only drawn when display_target is defined - can be extended to work without display_target - as a separate PR

Questions:

  • added with_line_numbers test - what other tests do we need?
  • should pretty still print line_numbers if this option is disabled?

@pmnoxx pmnoxx requested review from a team, davidbarsky and hawkw as code owners December 26, 2021 23:18
@hawkw
Copy link
Member

hawkw commented Dec 28, 2021

This seems like a duplicate of PR #1773, so we'll have to decide which one should be merged. I believe #1773 adds slightly more functionality (it also adds the option to display file paths...)

@hawkw hawkw closed this in 6f23c12 Jan 14, 2022
hawkw added a commit that referenced this pull request Jan 14, 2022
## Motivation

Logging line numbers and file names can be useful for debugging. This
feature was suggested by #1326

## Solution

As per @hawkw's suggestions, fields were added on `Format`, along with
builder methods. Filename and line number information was gathered from
the `meta` variable.

The `Pretty` formatter already supports printing source locations, but
this is configured separately on the `Pretty` formatter rather than on
the `Format` type. This branch also changes `Pretty` to honor the
`Format`-level configurations and deprecates the `Pretty`-specific
method.

Fixes #1326 Closes #1804

Co-authored-by: David Barsky <me@davidbarsky.com>
Co-authored-by: Eliza Weisman <eliza@buoyant.io>
@pmnoxx pmnoxx deleted the piotr-print-line-number-feature branch January 14, 2022 19:18
hawkw added a commit that referenced this pull request Jan 14, 2022
## Motivation

Logging line numbers and file names can be useful for debugging. This
feature was suggested by #1326

## Solution

As per @hawkw's suggestions, fields were added on `Format`, along with
builder methods. Filename and line number information was gathered from
the `meta` variable.

The `Pretty` formatter already supports printing source locations, but
this is configured separately on the `Pretty` formatter rather than on
the `Format` type. This branch also changes `Pretty` to honor the
`Format`-level configurations and deprecates the `Pretty`-specific
method.

Fixes #1326 Closes #1804

Co-authored-by: David Barsky <me@davidbarsky.com>
Co-authored-by: Eliza Weisman <eliza@buoyant.io>
kaffarell pushed a commit to kaffarell/tracing that referenced this pull request May 22, 2024
…1773)

## Motivation

Logging line numbers and file names can be useful for debugging. This
feature was suggested by tokio-rs#1326

## Solution

As per @hawkw's suggestions, fields were added on `Format`, along with
builder methods. Filename and line number information was gathered from
the `meta` variable.

The `Pretty` formatter already supports printing source locations, but
this is configured separately on the `Pretty` formatter rather than on
the `Format` type. This branch also changes `Pretty` to honor the
`Format`-level configurations and deprecates the `Pretty`-specific
method.

Fixes tokio-rs#1326 Closes tokio-rs#1804

Co-authored-by: David Barsky <me@davidbarsky.com>
Co-authored-by: Eliza Weisman <eliza@buoyant.io>
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