Class: Sapience::Subscriber

Inherits:
Base
  • Object
show all
Extended by:
Descendants
Defined in:
lib/sapience/subscriber.rb

Direct Known Subclasses

Appender::Stream, Appender::Wrapper

Instance Attribute Summary collapse

Attributes inherited from Base

#filter, #log_hooks

Instance Method Summary collapse

Methods included from Descendants

descendants

Methods inherited from Base

#fast_tag, #level=, #payload, #pop_tags, #push_tags, #silence, #tagged, #tags, #with_payload

Methods included from LogMethods

#debug, #debug?, #error, #error!, #error?, #fatal, #fatal!, #fatal?, #info, #info?, #level_to_index, #log_with_exception, #log_with_level, #measure, #measure_debug, #measure_error, #measure_fatal, #measure_info, #measure_trace, #measure_warn, #trace, #trace?, #warn, #warn?

Instance Attribute Details

#app_nameObject

Allow app_name to be set globally or per subscriber



56
57
58
# File 'lib/sapience/subscriber.rb', line 56

def app_name
  @app_name || Sapience.app_name
end

#formatterObject

Every logger has its own formatter



8
9
10
# File 'lib/sapience/subscriber.rb', line 8

def formatter
  @formatter
end

#hostObject

Allow host name to be set globally or per subscriber



61
62
63
# File 'lib/sapience/subscriber.rb', line 61

def host
  @host || Sapience.config.host
end

Instance Method Details

#closeObject

A subscriber should implement close if it can.



46
47
48
# File 'lib/sapience/subscriber.rb', line 46

def close
  # NOOP
end

#default_formatterObject

Returns [Sapience::Formatters::Default] formatter default for this subscriber



51
52
53
# File 'lib/sapience/subscriber.rb', line 51

def default_formatter
  Sapience::Formatters::Default.new
end

#flushObject

A subscriber should implement flush if it can.



19
20
21
# File 'lib/sapience/subscriber.rb', line 19

def flush
  # NOOP
end

#levelObject

Returns the current log level if set, otherwise it logs everything it receives



14
15
16
# File 'lib/sapience/subscriber.rb', line 14

def level
  @level || :trace
end

#nameObject



41
42
43
# File 'lib/sapience/subscriber.rb', line 41

def name
  self.class.name
end

#to_sObject

TODO: Implement a format string with class name and interesting values see:

- https://www.rubysteps.com/articles/2015/customize-your-ruby-classes-with-to-s-and-inspect/
- http://stackoverflow.com/questions/9524698/override-to-s-while-keeping-output-of-inspect
- http://stackoverflow.com/questions/2625667/why-do-this-ruby-object-have-both-to-s-and-inspect-methods-that-appear-to-do-the


37
38
39
# File 'lib/sapience/subscriber.rb', line 37

def to_s
  name
end

#valid?Boolean

TODO: Implement this mehtod in all appenders TODO: Output relevant message when appender isn’t valid TODO: Check this valid? method before using appender, output above error message if not valid? TODO: Wait with adding appenders until they are needed solve this by below TODO: Implement possibility of finding and deleting appenders by env

Returns:

  • (Boolean)


28
29
30
# File 'lib/sapience/subscriber.rb', line 28

def valid?
  fail NotImplementedError, "needs to be implemented in appender"
end