This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
# encoding: utf-8
|
||||
|
||||
require_relative '../lib/yell'
|
||||
|
||||
puts <<-EOS
|
||||
|
||||
# On the basics, Yell works just like any other logging library.
|
||||
#
|
||||
# However, it enriches your log messages to make it more readable. By default,
|
||||
# it will format the given message as follows:
|
||||
|
||||
logger = Yell.new STDOUT
|
||||
logger.info "Hello World!"
|
||||
|
||||
#=> "2012-02-29T09:30:00+01:00 [ INFO] 65784 : Hello World!"
|
||||
# ^ ^ ^ ^
|
||||
# ISO8601 Timestamp Level Pid Message
|
||||
|
||||
|
||||
EOS
|
||||
|
||||
puts "=== actual example ==="
|
||||
logger = Yell.new STDOUT
|
||||
logger.info "Hello World!"
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
# encoding: utf-8
|
||||
|
||||
require_relative '../lib/yell'
|
||||
|
||||
puts <<-EOS
|
||||
|
||||
# Like many other logging libraries, Yell allows you to define from which level
|
||||
# onwards you want to write your log message.
|
||||
|
||||
logger = Yell.new STDOUT, level: :info
|
||||
|
||||
logger.debug "This is a :debug message"
|
||||
#=> nil
|
||||
|
||||
logger.info "This is a :info message"
|
||||
#=> "2012-02-29T09:30:00+01:00 [ INFO] 65784 : This is a :info message"
|
||||
|
||||
|
||||
EOS
|
||||
|
||||
puts "=== actual example ==="
|
||||
logger = Yell.new STDOUT, level: :info
|
||||
|
||||
logger.debug "This is a :debug message"
|
||||
logger.info "This is a :info message"
|
||||
@@ -0,0 +1,29 @@
|
||||
# encoding: utf-8
|
||||
|
||||
require_relative '../lib/yell'
|
||||
|
||||
puts <<-EOS
|
||||
|
||||
# The Yell::Level parser allows you to exactly specify on which levels to log,
|
||||
# ignoring all the others. For instance: If we want to only log at the :debug
|
||||
# and :warn levels we simply providing an array:
|
||||
# * %i[] is a built-in for an array of symbols
|
||||
|
||||
logger = Yell.new STDOUT, level: %i[debug warn]
|
||||
|
||||
%i[debug info warn error fatal].each do |level|
|
||||
logger.send( level, level )
|
||||
end
|
||||
#=> "2012-02-29T09:30:00+01:00 [DEBUG] 65784 : debug"
|
||||
#=> "2012-02-29T09:30:00+01:00 [ WARN] 65784 : warn"
|
||||
|
||||
|
||||
EOS
|
||||
|
||||
puts "=== actual example ==="
|
||||
logger = Yell.new STDOUT, level: %i[debug warn]
|
||||
|
||||
%i[debug info warn error fatal].each do |level|
|
||||
logger.send( level, level )
|
||||
end
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
# encoding: utf-8
|
||||
|
||||
require_relative '../lib/yell'
|
||||
|
||||
puts <<-EOS
|
||||
|
||||
# Additionally to writing only on specific levels, you may pass a range to
|
||||
# the :level option:
|
||||
# * %i[] is a built-in for an array of symbols
|
||||
|
||||
|
||||
logger = Yell.new STDOUT, level: (:debug..:warn)
|
||||
|
||||
%i[debug info warn error fatal].each do |level|
|
||||
logger.send( level, level )
|
||||
end
|
||||
#=> "2012-02-29T09:30:00+01:00 [DEBUG] 65784 : debug"
|
||||
#=> "2012-02-29T09:30:00+01:00 [ INFO] 65784 : info"
|
||||
#=> "2012-02-29T09:30:00+01:00 [ WARN] 65784 : warn"
|
||||
|
||||
|
||||
EOS
|
||||
|
||||
puts "=== actual example ==="
|
||||
logger = Yell.new STDOUT, level: (:debug..:warn)
|
||||
|
||||
%i[debug info warn error fatal].each do |level|
|
||||
logger.send( level, level )
|
||||
end
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
# encoding: utf-8
|
||||
|
||||
require_relative '../lib/yell'
|
||||
|
||||
puts <<-EOS
|
||||
|
||||
# The default formatting string looks like: %d [%5L] %p : %m and is used when
|
||||
# nothing else is defined.
|
||||
|
||||
logger = Yell.new STDOUT, format: Yell::DefaultFormat
|
||||
logger.info "Hello World!"
|
||||
#=> "2012-02-29T09:30:00+01:00 [ INFO] 65784 : Hello World!"
|
||||
# ^ ^ ^ ^
|
||||
# ISO8601 Timestamp Level Pid Message
|
||||
|
||||
|
||||
EOS
|
||||
|
||||
puts "=== actual example ==="
|
||||
logger = Yell.new STDOUT, format: Yell::DefaultFormat
|
||||
logger.info "Hello World!"
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
# encoding: utf-8
|
||||
|
||||
require_relative '../lib/yell'
|
||||
|
||||
puts <<-EOS
|
||||
|
||||
# The basic formating string looks like: %l, %d: %m.
|
||||
|
||||
logger = Yell.new STDOUT, format: Yell::BasicFormat
|
||||
logger.info "Hello World!"
|
||||
#=> "I, 2012-02-29T09:30:00+01:00 : Hello World!"
|
||||
# ^ ^ ^
|
||||
# ^ ISO8601 Timestamp Message
|
||||
# Level (short)
|
||||
|
||||
|
||||
EOS
|
||||
|
||||
puts "=== actual example ==="
|
||||
logger = Yell.new STDOUT, format: Yell::BasicFormat
|
||||
logger.info "Hello World!"
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
# encoding: utf-8
|
||||
|
||||
require_relative '../lib/yell'
|
||||
|
||||
puts <<-EOS
|
||||
|
||||
# The extended formatting string looks like: %d [%5L] %p %h : %m.
|
||||
|
||||
logger = Yell.new STDOUT, format: Yell::ExtendedFormat
|
||||
logger.info "Hello World!"
|
||||
#=> "2012-02-29T09:30:00+01:00 [ INFO] 65784 localhost : Hello World!"
|
||||
# ^ ^ ^ ^ ^
|
||||
# ISO8601 Timestamp Level Pid Hostname Message
|
||||
|
||||
|
||||
EOS
|
||||
|
||||
puts "=== actual example ==="
|
||||
logger = Yell.new STDOUT, format: Yell::ExtendedFormat
|
||||
logger.info "Hello World!"
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
# encoding: utf-8
|
||||
|
||||
require_relative '../lib/yell'
|
||||
|
||||
puts <<-EOS
|
||||
|
||||
# The extended formatting string looks like: %d [%5L] %p %h : %m.
|
||||
|
||||
logger = Yell.new STDOUT, format: "[%f:%n in `%M'] %m", trace: true
|
||||
logger.info "Hello World!"
|
||||
#=> [003.4-formatting-on-your-own.rb:20 in `<main>'] Hello World!
|
||||
# ^ ^ ^ ^
|
||||
# filename line method message
|
||||
|
||||
|
||||
EOS
|
||||
|
||||
puts "=== actual example ==="
|
||||
logger = Yell.new STDOUT, format: "[%f:%n in `%M'] %m", trace: true
|
||||
logger.info "Hello World!"
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
# encoding: utf-8
|
||||
|
||||
require_relative '../lib/yell'
|
||||
|
||||
puts <<-EOS
|
||||
|
||||
You may colorize the log output on your io-based loggers loke so:
|
||||
|
||||
logger = Yell.new STDOUT, colors: true
|
||||
|
||||
Yell::Severities.each do |level|
|
||||
logger.send level.downcase, level
|
||||
end
|
||||
|
||||
EOS
|
||||
|
||||
puts "=== actual example ==="
|
||||
logger = Yell.new STDOUT, colors: true
|
||||
|
||||
Yell::Severities.each do |level|
|
||||
logger.send level.downcase, level
|
||||
end
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
# encoding: utf-8
|
||||
|
||||
require_relative '../lib/yell'
|
||||
|
||||
puts <<-EOS
|
||||
|
||||
# You can add a logger to the global repository.
|
||||
#
|
||||
# create a logger named 'mylog' that logs to stdout
|
||||
Yell.new :stdout, name: 'mylog'
|
||||
|
||||
# Later in the code, you can get your logger back
|
||||
Yell['mylog'].info "Hello World!"
|
||||
|
||||
|
||||
EOS
|
||||
|
||||
puts "=== actual example ==="
|
||||
Yell.new :stdout, name: 'mylog'
|
||||
Yell['mylog'].info "Hello World!"
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
# encoding: utf-8
|
||||
|
||||
require_relative '../lib/yell'
|
||||
|
||||
puts <<-EOS
|
||||
|
||||
# You can add logging to any class by including the Yell::Loggable module.
|
||||
#
|
||||
# When including the module, your class will get a :logger method. Before you
|
||||
# can use it, though, you will need to define a logger providing the :name of
|
||||
# your class.
|
||||
|
||||
Yell.new :stdout, name: 'Foo'
|
||||
|
||||
# Define the class
|
||||
class Foo
|
||||
include Yell::Loggable
|
||||
end
|
||||
|
||||
foo = Foo.new
|
||||
foo.logger.info "Hello World!"
|
||||
#=> "2012-02-29T09:30:00+01:00 [ INFO] 65784 : Hello World!"
|
||||
|
||||
|
||||
EOS
|
||||
|
||||
puts "=== actual example ==="
|
||||
|
||||
Yell.new :stdout, name: 'Foo'
|
||||
|
||||
class Foo
|
||||
include Yell::Loggable
|
||||
end
|
||||
|
||||
foo = Foo.new
|
||||
foo.logger.info "Hello World!"
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
# encoding: utf-8
|
||||
|
||||
require_relative '../lib/yell'
|
||||
|
||||
puts <<-EOS
|
||||
|
||||
# You can add logging to any class by including the Yell::Loggable module.
|
||||
#
|
||||
# When including the module, your class will get a :logger method. Before you
|
||||
# can use it, though, you will need to define a logger providing the :name of
|
||||
# your class.
|
||||
|
||||
Yell.new :stdout, name: 'Foo'
|
||||
|
||||
# Define the class
|
||||
class Foo
|
||||
include Yell::Loggable
|
||||
end
|
||||
|
||||
class Bar < Foo; end
|
||||
|
||||
bar = Bar.new
|
||||
bar.logger.info "Hello World!"
|
||||
#=> "2012-02-29T09:30:00+01:00 [ INFO] 65784 : Hello World!"
|
||||
|
||||
|
||||
EOS
|
||||
|
||||
puts "=== actual example ==="
|
||||
|
||||
Yell.new :stdout, name: 'Foo'
|
||||
|
||||
class Foo
|
||||
include Yell::Loggable
|
||||
end
|
||||
|
||||
class Bar < Foo; end
|
||||
|
||||
bar = Bar.new
|
||||
bar.logger.info "Hello World!"
|
||||
|
||||
Reference in New Issue
Block a user