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

replace forwarders with a Component class that is not a full Logger #3

Open
wants to merge 1 commit into
base: logger2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/logger.cr
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require "logger/component"
require "logger/emitter"
require "logger/entry"
require "logger/filter"
require "logger/emitter"
require "logger/severity"

class Logger
Expand Down Expand Up @@ -31,6 +32,10 @@ class Logger
log Entry.new(message, Severity::{{ level }}, component, time, line_number, filename)
end
{% end %}

def get(component)
Component.new(component.to_s, self)
end
end

include Base
Expand All @@ -46,10 +51,6 @@ class Logger
class_property filter : FilterType?
class_property emitter : EmitterType? = IOEmitter.new

def self.get(component)
Logger.new(component.to_s, nil, Forwarder.new(self))
end

{% for level in Severity.constants %}
{{ level }} = Severity::{{ level }}
{% end %}
Expand Down
21 changes: 21 additions & 0 deletions src/logger/component.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
require "./severity"

class Logger
class Component
getter logger : Base
getter name : String

def initialize(@name, @logger)
end

{% for level in Severity.constants %}
def {{ level.downcase.id }}(*, time = Time.now, line_number = __LINE__, filename = __FILE__, &message : -> String)
@logger.log Entry.new(message, Severity::{{ level }}, name, time, line_number, filename)
end

def {{ level.downcase.id }}(message, *, time = Time.now, line_number = __LINE__, filename = __FILE__)
@logger.log Entry.new(message, Severity::{{ level }}, name, time, line_number, filename)
end
{% end %}
end
end
13 changes: 0 additions & 13 deletions src/logger/emitter.cr
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,4 @@ class Logger
@formatter.call(@io, entry)
end
end

class Forwarder
include Emitter

getter dest : Base

def initialize(@dest)
end

def call(entry : Entry)
dest.log(entry)
end
end
end