Skip to content

Commit

Permalink
Merge pull request #9 from place-labs/feat/support-stdout-json
Browse files Browse the repository at this point in the history
feat: support for JSON stdout
  • Loading branch information
stakach authored Sep 27, 2021
2 parents 0fbda34 + dd194e9 commit 2007d6f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
2 changes: 1 addition & 1 deletion shard.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: placeos-log-backend
version: 0.5.1
version: 0.6.0
crystal: ~> 1
license: MIT

Expand Down
30 changes: 18 additions & 12 deletions src/placeos-log-backend.cr
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,17 @@ require "log"
require "./ext/log/broadcast_backend"

module PlaceOS::LogBackend
Log = ::Log.for(self)
STDOUT = ActionController.default_backend
enum Format
Line
JSON
end

Log = ::Log.for(self)

STDOUT = ActionController.default_backend

LOG_FORMAT = ENV["PLACE_LOG_FORMAT"]?.presence.try { |format| Format.parse format } || Format::Line

UDP_LOG_HOST = self.env_with_deprecation("UDP_LOG_HOST", "LOGSTASH_HOST")
UDP_LOG_PORT = self.env_with_deprecation("UDP_LOG_PORT", "LOGSTASH_PORT").try &.to_i?

Expand Down Expand Up @@ -85,20 +94,17 @@ module PlaceOS::LogBackend
Signal::USR2.trap &logging
end

@[Deprecated("Use `udp_log_host` and `udp_log_port` arguments.")]
def self.log_backend(
logstash_host : String? = UDP_LOG_HOST,
logstash_port : Int32? = UDP_LOG_PORT,
default_backend : ::Log::IOBackend = ActionController.default_backend
)
log_backend(udp_log_host: logstash_host, udp_log_port: logstash_port)
end

def self.log_backend(
udp_log_host : String? = UDP_LOG_HOST,
udp_log_port : Int32? = UDP_LOG_PORT,
default_backend : ::Log::IOBackend = ActionController.default_backend
default_backend : ::Log::IOBackend = ActionController.default_backend,
format : Format = LOG_FORMAT
)
case format
in .line? then default_backend.formatter = ActionController.default_formatter
in .json? then default_backend.formatter = ActionController.json_formatter
end

return default_backend if udp_log_host.nil?

abort("UDP_LOG_PORT is either malformed or not present in environment") if udp_log_port.nil?
Expand Down

0 comments on commit 2007d6f

Please sign in to comment.