luckyframework / dexter

A logger with maximum customizability and surgical precision
MIT License
21 stars 4 forks source link

Logging model records #10

Closed jwoertink closed 4 years ago

jwoertink commented 5 years ago

If you have a model instance, and you want to log that, right now you might use pp. If you try and pass this to Lucky.logger.info, you'll find that nothing happens. No compile error, no output.

# This does nothing
Lucky.logger.info(UserQuery.first)

# This throws an error about undefined method to_json
Lucky.logger.info({record: UserQuery.first})

I'm thinking maybe the first way throws a compile-time error, and then we add a special method like inspect or whatever to models.

# error: If you're trying to log a model, be sure to call #inspect
Lucky.logger.info(UserQuery.first)

Lucky.logger.info(UserQuery.first.inspect)

Side related: https://github.com/luckyframework/lucky/issues/950

paulcsmith commented 5 years ago

My gut feeling here is that we should figure out why Lucky.logger.info(UserQuery.first) doesn't work because I think it should print something or fail to compile (like you mentioned). My thought is that it should just work by calling inspect or whatever pp does under the hood

paulcsmith commented 4 years ago

This is no longer an issue in 0.2.0. It will fail if not returning a Hash or NamedTuple, and if you use the built-in Log it will call to_s on it. Probably best to add a better inspect to models too but I'll close this one for now since the logger side is done

Also we can add a request id in 0.2.0. Working on that this weekend!