fluent-logger-ruby icon indicating copy to clipboard operation
fluent-logger-ruby copied to clipboard

Discard the millisecond of the Time value

Open Watson1978 opened this issue 3 months ago • 1 comments

When it fails to serialize data to MsgPack format, it falls back to part using JSON.parse(JSON.generate(msg)).to_msgpack.

https://github.com/fluent/fluent-logger-ruby/blob/6bcebac554ceb8d5368fbfa128336fa4b49c8225/lib/fluent/logger/fluent_logger.rb#L233-L244

The fallback part discard the millisecond of the Time value. There are cases where people dislike it.

Example:

require "bundler/inline"
gemfile do
  source "https://rubygems.org"
  gem "fluent-logger"
  gem "activesupport"
end

require 'active_support/json'

log = Fluent::Logger::FluentLogger.new(nil, :host => 'localhost', :port => 24224)

log.post("myapp.access", { user: "foo", created_at: Time.now })
log.post("myapp.access", { user: "foo", created_at: Time.now.as_json })

Beforehand, it preserves milliseconds converting with as_json. (If active_support is loaded, to_json will invoke as_json automatically.)

This behavior is preferred by default.

2025-09-19 11:54:11.000000000 +0900 incoming: {"user":"foo","created_at":"2025-09-19 11:54:11 +0900"}
2025-09-19 11:54:11.000000000 +0900 incoming: {"user":"foo","created_at":"2025-09-19T11:54:11.828+09:00"}

We need to regist custom MsgPack packer for Time object, or something...

Watson1978 avatar Sep 19 '25 03:09 Watson1978