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

logging without newline #533

Closed
efendioglukdz opened this issue Oct 31, 2022 · 9 comments
Closed

logging without newline #533

efendioglukdz opened this issue Oct 31, 2022 · 9 comments

Comments

@efendioglukdz
Copy link

Hello folks,

is it possible that I put a logline without a implicit newline at the end of the line? the macro log::info!() puts always a new line at the end.
It would be nice if I had the possibility to distinguish it like the print! or println! macro it does!!!!

@Thomasdezeeuw
Copy link
Collaborator

I don't think the info! macro adds a new line, the log implementation (that handles the actual logging) does that for you. You could change the implementation and simply not print a new line.

@efendioglukdz
Copy link
Author

When I put
log::info!("Line1");
log::info!("Line2");
there is implicitely a newline between them. Mayb I dnt get it right, but where can I prevent this?

@sfackler
Copy link
Member

You are using some specific logging implementation that is deciding to put a newline between them. This crate doesn't have any control over that.

@efendioglukdz
Copy link
Author

Well, I guess u mean flexi_logger.

@efendioglukdz
Copy link
Author

ur right.
its decided in
.format_for_files(|w, now, record| { write!( w, "{};{: >7};{}", &format!("{}-{:02}-{:02} {:02}:{:02}:{:02}:{:03}",now.now().year(),now.now().month() as i32,now.now().day(),now.now().hour(),now.now().minute(),now.now().second(),now.now().millisecond()), &format!("[{}]",record.level()), &record.args() ) })
in the write! macro:
macro_rules! write { ($dst:expr, $($arg:tt)*) => { $dst.write_fmt($crate::format_args!($($arg)*)) }; }

I guess format_args! makes an newline

@Thomasdezeeuw
Copy link
Collaborator

Thomasdezeeuw commented Oct 31, 2022

I guess format_args! makes an newline

No it doesn't. The flexi_logger implementation adds the new line.

@NobodyXu
Copy link

I guess format_args! makes an newline

No, it doesn't and that's why rust introduces format_args_ln! which introduces a newline at the end.

@robsdedude
Copy link

robsdedude commented Feb 14, 2023

Even if it's not baked into the log crate, it's still somewhat implied that each call to log! represents another log entry which most logger implementations will separate somehow. Be it a new line or another row in a data store or whatever. I still find the idea of this issue compelling. What if there was a macro a la log_but_wait_theres_more! and log_ok_entry_done!? ofc. those names are bullocks. They could be expanded to a check if logging is enabled and if so, prepare the log message in a String buffer or similar.

EDIT: looking through the crate code and familiarizing myself with std::fmt::Arguments and alike makes me realize it's not that straight forward. So while I'm no longer sure there's a technical solution to this, I'd still find it useful to have such functionality.

@KodrAus
Copy link
Contributor

KodrAus commented Apr 13, 2023

The concept of building up an event over an operation and emitting in a single blob at the end is sometimes called a "wide event". You can also do it using tracing, where multiple events are emitted within a single span.

It is an interesting concept, but not one that I think exists at the level of abstraction this crate is concerned with. An implementation of Log can decide whether or not a series of calls belong to the same entity or not.

I'll go ahead and close this one as the specific issue isn't related to log.

@KodrAus KodrAus closed this as completed Apr 13, 2023
EFanZh pushed a commit to EFanZh/log that referenced this issue Jul 23, 2023
Bumps [mimalloc](https://github.com/purpleprotocol/mimalloc_rust) from 0.1.31 to 0.1.32.
- [Release notes](https://github.com/purpleprotocol/mimalloc_rust/releases)
- [Commits](purpleprotocol/mimalloc_rust@v0.1.31...v0.1.32)

---
updated-dependencies:
- dependency-name: mimalloc
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
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

No branches or pull requests

6 participants