# frozen_string_literal: true require_relative "teLogger/version" require_relative 'teLogger/tlogger' require_relative 'teLogger/logger_group' module TeLogger class Error < StandardError; end # Your code goes here... # for classes including the TeLogger module TeLogHelper module ClassMethods # methods called at class level by included class # However if TeLogHelper is included inside Module1, only Module1 is included in Class1, # Class1 will not be able to access the class level method here. def teLogger_tag(val) @telTag = val end def teLogger_output(*val) @telOutput = val end def logTag @telTag end def logOutput if @telOutput.nil? [] elsif not @telOutput.is_a?(Array) [@telOutput] else @telOutput end end end # ClassMethods def self.included(klass) puts "TeLogHelper : #{klass}" klass.extend(ClassMethods) klass.extend(TeLogHelper) end #def logOutput=(val) # @logOut = val #end #def logOutput # if self.class.respond_to?(:logOutput) # self.class.logOutput # else # @logOut # end #end private def teLogger if @teLogger.nil? if self.class.respond_to?(:logOutput) intLogger.debug "Class logOutput is #{self.class.logOutput}" @teLogger = Tlogger.new(*self.class.logOutput) elsif self.respond_to?(:logOutput) intLogger.debug "logOutput is #{logOutput}" @teLogger = Tlogger.new(*logOutput) else intLogger.debug "logOutput is not available in #{self}. Please note TeLogHelper mixin only works properly on directly included class/module. Fall back to console only" @teLogger = Tlogger.new end if self.respond_to?(:logTag) @teLogger.tag = logTag elsif self.class.respond_to?(:logTag) @teLogger.tag = self.class.logTag end end @teLogger end def intLogger if @intLogger.nil? intLogOut = ENV['TELOGGER_INTLOG_OUT'] if intLogOut.nil? or intLogOut.empty? @intLogger = Tlogger.new else intLogOut = [intLogOut] if not intLogOut.is_a?(Array) @intLogger = Tlogger.new(*intLogOut) end end @intLogger end end end TeLogger::Helper = TeLogger::TeLogHelper