Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Take timestamp as an argument in Log::Entry initializer #9570

Conversation

Sija
Copy link
Contributor

@Sija Sija commented Jul 3, 2020

I want to store re-created Log::Entries from another logging system. In order to do so I need to set Log::Entry#timestamp property, which atm is being set to Time.local on object creation.

@asterite
Copy link
Member

asterite commented Jul 3, 2020

I think this is fine, but could you explain a bit the use case?

@Sija
Copy link
Contributor Author

Sija commented Jul 3, 2020

Example of a Logger -> Log::Backend bridge:

require "logger"

class Logger
  protected getter __log_backend : Log::Backend { LoggerBackendBridge.new }

  private def write(severity, datetime, progname, message)
    level = Log::Severity.parse?(severity.to_s) || Log::Severity::Debug

    __log_backend.write Log::Entry.new(
      source: progname.to_s,
      severity: level,
      message: message.to_s,
      data: Log::Metadata.new,
      exception: nil,
      timestamp: datetime, # <- Impossible
    )
    previous_def
  end
end

@z64
Copy link
Contributor

z64 commented Jul 3, 2020

This is 👍 from me -

In our application stack, we migrated from an in-house logging stack (custom web UI for reviewing telemetry in graphs, statistics, etc.) that was backed by postgres. Starting with 0.34, we moved to an ELK stack, in which we emit logs using the new Log API. We still have that large backlog of log data collected in postgres - being able to create an Entry "resurrected" from these custom postgres rows to emit to our ELK stack is likely the approach we will take, as its a very short script to do so - which this patch would support.

Another small note, I monkeypatch setter timestamp into Entry in our spec suite to test our custom logging formatter's output to set a predetermined timestamp so that formatter output is the same each time. This patch would also remove that, so I can just use the constructor.

@Blacksmoke16
Copy link
Member

Blacksmoke16 commented Jul 3, 2020

Does it make sense for the timestamp to not be UTC? I would think UTC would make more sense, especially when trying to consume the logs generated by two applications in two different regions.

@Sija
Copy link
Contributor Author

Sija commented Jul 5, 2020

Does this needs any further clarifications, or can I get a review so we could get the ball rollin'?

@asterite
Copy link
Member

asterite commented Jul 5, 2020

@Sija It's weekend, probably not many people are reviewing code.

@asterite
Copy link
Member

asterite commented Jul 5, 2020

Plus the core team has an agenda, and these PRs just take time off of that agenda. So they will be reviewed, but with time.

@Sija
Copy link
Contributor Author

Sija commented Jul 5, 2020

Plus the core team has an agenda, and these PRs just take time off of that agenda. So they will be reviewed, but with time.

I reckon that, though I'm sure that a 2 line change won't take too much time off the agenda...

@straight-shoota
Copy link
Member

@Blacksmoke16 Would you open a new issue for discussing the default value? That's a different topic.

@bcardiff
Copy link
Member

bcardiff commented Jul 9, 2020

I would prefer if the timestamp is moved to a named argument. If we want to add more data to the entry having timestamp there will be inconvenient.

@Sija Sija force-pushed the allow-initialization-of-log-entry-timestamp branch from fd9c0dc to 1e6a09d Compare August 3, 2020 15:38
@Sija
Copy link
Contributor Author

Sija commented Aug 3, 2020

@bcardiff Done. Should be GTG now.

@Sija
Copy link
Contributor Author

Sija commented Aug 10, 2020

Anything left to do here?

@straight-shoota straight-shoota merged commit afcb3f4 into crystal-lang:master Aug 13, 2020
@straight-shoota straight-shoota added this to the 1.0.0 milestone Aug 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants