-
Notifications
You must be signed in to change notification settings - Fork 78
Open
Description
When it fails to serialize data to MsgPack format,
it falls back to part using JSON.parse(JSON.generate(msg)).to_msgpack.
fluent-logger-ruby/lib/fluent/logger/fluent_logger.rb
Lines 233 to 244 in 6bcebac
| def to_msgpack(msg) | |
| @mon.synchronize { | |
| res = begin | |
| @packer.pack(msg).to_s | |
| rescue NoMethodError | |
| JSON.parse(JSON.generate(msg)).to_msgpack | |
| ensure | |
| @packer.clear | |
| end | |
| res | |
| } | |
| end |
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...
Metadata
Metadata
Assignees
Labels
No labels