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

Control precision of floating point logging #36

Open
cossio opened this issue Dec 7, 2022 · 1 comment
Open

Control precision of floating point logging #36

cossio opened this issue Dec 7, 2022 · 1 comment

Comments

@cossio
Copy link

cossio commented Dec 7, 2022

Suppose x is a float. I show it with:

@info x

Usually this prints x with full precision. Is there a way to control the formatting (e.g. number of digits) of floating points ?

@Arkoniak
Copy link
Collaborator

Arkoniak commented Feb 9, 2023

Since there can be arbitrary amount of arguments of any type, it's hardly reasonable to add formatting rules to logging facilities. So, there are two ways to control the formatting:

  1. Internally Miniloggers.jl uses string function to create output. So, you can pirate string function for corresponding type and redefine it.
  2. You can use @sprintf or any other similar facilities to control output for each argument. Of course, it can be tedious, but it just work.

Well, expanding on 1. I can define something like present(x) = string(x) and use it for output. This way, you'll need to redefine only present function, which is still a piracy, but not as dramatic as redefining string.

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

2 participants