fluent / fluent/fluent-logger-ruby

Discard the millisecond of the Time value

Open
#111 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Ruby
Stars
256
Forks
77
PR merge metrics
No merged PRs in 30d

Description

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:

```ruby
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...

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.