lib/nrser/log/mixin.rb
# Gets the {NRSER::Log::Logger} for use in the instance. This will be the
# class logger from {ClassMethods#logger} unless the instance has a
# `#create_logger` method.
# 
# The `#create_logger` method is expected to return a {NRSER::Log::Logger}
# instance, which will be saved in the `@semantic_logger` instance variable
# for future use.
# 
# That method does not need to return a different logger for every instance
# - if you just want to have a different logger for *all* instance with a
# different level or formatter or whatever, you can save it somewhere else
# and always return that same instance.
# 
# If you are dealing with frozen instances make sure to call `#logger` before
# you freeze (likely in the constructor). If you don't want to save the
# logger at all, just override this method itself.
# 
# This is a departure from {SemanticLogger::Loggable} that started because
# if the instance is frozen then attempting to set `@semantic_logger` will
# raise an error.
# 
# I also started ending up with classes that wanted to individually
# configure their loggers, so it seemed like we could take out two birds
# with this stone.
# 
# @return [SemanticLogger::Logger]
#   Instance level logger, if {ClassMethods.instance_logger?},
#   otherwise the class level logger from {ClassMethods#logger}.
# 
Gets the {NRSER::Log::Logger} for use in the instance. This will be the
class logger from {ClassMethods#logger} unless the instance has a
`#create_logger` method.

The `#create_logger` method is expected to return a {NRSER::Log::Logger}
instance, which will be saved in the `@semantic_logger` instance variable
for future use.

That method does not need to return a different logger for every instance
if you just want to have a different logger for *all* instance with a
different level or formatter or whatever, you can save it somewhere else
and always return that same instance.

If you are dealing with frozen instances make sure to call `#logger` before
you freeze (likely in the constructor). If you don't want to save the
logger at all, just override this method itself.

This is a departure from {SemanticLogger::Loggable} that started because
if the instance is frozen then attempting to set `@semantic_logger` will
raise an error.

I also started ending up with classes that wanted to individually
configure their loggers, so it seemed like we could take out two birds
with this stone.
Gets the { NRSER :: Log :: Logger } for use in the instance . This will be the class logger from { ClassMethods#logger } unless the instance has a ` #create_logger ` method . The ` #create_logger ` method is expected to return a { NRSER :: Log :: Logger } instance which will be saved in the ` @semantic_logger ` instance variable for future use . That method does not need to return a different logger for every instance if you just want to have a different logger for * all * instance with a different level or formatter or whatever you can save it somewhere else and always return that same instance . If you are dealing with frozen instances make sure to call ` #logger ` before you freeze ( likely in the constructor ) . If you don ' t want to save the logger at all just override this method itself . This is a departure from { SemanticLogger :: Loggable } that started because if the instance is frozen then attempting to set ` @semantic_logger ` will raise an error . I also started ending up with classes that wanted to individually configure their loggers so it seemed like we could take out two birds with this stone .
def logger
    return @semantic_logger if @semantic_logger
    if respond_to?( :create_logger, true )
      @semantic_logger = begin
        create_logger
      rescue Exception => error
        self.class.logger.warn \
          "Error creating instance logger",
          { instance: self.inspect },
          error
        self.class.logger
      end
    else
      self.class.logger
    end
  end
def logger return @semantic_logger if @semantic_logger if respond_to? ( :create_logger , true ) @semantic_logger = begin create_logger rescue Exception => error self . class . logger . warn "Error creating instance logger" , { instance : self . inspect } , error self . class . logger end else self . class . logger end end
Gets the {NRSER::Log::Logger} for use in the instance.
Gets the { NRSER :: Log :: Logger } for use in the instance .
Instance level logger, if {ClassMethods.instance_logger?}, otherwise the class level logger from {ClassMethods#logger}.
Instance level logger if { ClassMethods . instance_logger? } otherwise the class level logger from { ClassMethods#logger } .
SemanticLogger::Logger