samples/basic.rb in tlogger-0.8.0 vs samples/basic.rb in tlogger-0.21.0

- old
+ new

@@ -1,44 +1,62 @@ -# -# basic use case -# +require 'tlogger' -class Cls +log = Tlogger::Tlogger.new - # to get the with_tag() - include Tlogger - - def initialize - @log = Tlogger.new(STDOUT) - @log.tag = :cls - end +log.debug "Without tagging" +log.info "Without tagging" +log.warn "Without tagging" +log.error "Without tagging" - def bark - @log.debug "wuf wof" - end +# default tag for this loging session +log.tag = "global" - def say - with_tag(:say) do - @log.debug "inside say" - puts "Say hello world!" - @log.warn "after hello!" - end +log.debug { "With default tagging" } +log.info { "With default tagging" } +log.warn { "With default tagging" } +log.error { "With default tagging" } - @log.error "Error here..." - end +# include the file and location where the log message is printed out +log.include_caller = true +log.tdebug :mytag, "With per log message tagging" + +log.with_tag :block_tag do |log| + log.debug "Inside block" + log.info "inside block" + log.warn "inside block" + log.error "inside block" end -#if $0 == __FILE__ +log.debug "Outside block. Shall take default tag '#{log.tag}'" -#Tlogger::TloggerConf.auto_tag_on -#Tlogger::TloggerConf.disable_all_tags -#Tlogger::TloggerConf.disable_tag([:cls]) +log.debug "About to show log message only show once. This can be useful if it is a warning which only print out per run." +(0..4).each do |i| + # one time message tie to key + # Means if the message is under specific key and already prompted, it will skip + # Else it will be printed + log.odebug :debug_once, &-> { "this is one time message" } + log.oerror :error_once, "One time error" + log.oinfo :info_once, "One time info" + log.owarn :warn_once, "One time warning" + log.owarn :warn_once, "One time warning" # this line shall be skipped + log.oinfo :info_once, "One time info" # this line shall be skipped too + # from the output, even this is looped 5 times, only 4 messages shall be printed out +end -c = Cls.new -c.bark -c.say +log.info "Shall turned off all except tag :whatever" +log.off_all_except(:whatever,:global) +log.tdebug :another_global, "I've been turned off" # this line shall not show in the log output +log.terror :whatever, "I will survive!" # this line will show up because it is being exampted +log.tinfo :global, "Got turned off" # this line will show up because it is being exampted -#end +log.remove_from_exception(:global) +log.twarn :global, "Since :global is removed from exception, will it print out?" # this line will not show up because it has removed from examption and shall be off +log.on_all_except(:global) +log.tdebug :another_global, "Now it is my turn to be here" # this line will show up because all is on +log.terror :whatever, "Yeah me too!" # this line will show up because all is on +log.debug "I'm inherited from key :global so I'm also not visible" # due to on_all_except(:global) this line shall not be printed +log.tinfo :global, "Gosh! I've been turned off by default" # due to on_all_except(:global) this line shall not be printed +log.twarn :local, "I'm free!" # this line will show up because all is on