JuliaLogging / MiniLoggers.jl

Julia logger with customizable logging string
MIT License
13 stars 2 forks source link

Control precision of floating point logging #36

Open cossio opened 1 year ago

cossio commented 1 year ago

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 commented 1 year ago

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.