forked from colbygk/log4r
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request colbygk#1 from jablan/master
patch for yamlconfigurator
- Loading branch information
Showing
4 changed files
with
113 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
$: << File.join('..','lib') # path if log4r is not installed | ||
require "test/unit" | ||
require 'log4r' | ||
require 'log4r/yamlconfigurator' | ||
include Log4r | ||
|
||
# Define a custom outputter that allows arrays in configuration hash | ||
module Log4r | ||
class TestYamlOutputter < Outputter | ||
# expose array parameter | ||
attr_reader :array_param | ||
|
||
def initialize(name, hash = {}) | ||
@array_param = hash['array_param'] | ||
end | ||
end | ||
end | ||
|
||
|
||
class TestYaml < Test::Unit::TestCase | ||
|
||
def setup | ||
@cfg = YamlConfigurator # shorthand | ||
@cfg['CUSTOM_DOMAIN'] = 'bar.com' | ||
end | ||
|
||
def test_injection | ||
assert_nothing_raised("Exception injected") do | ||
@cfg.load_yaml_file(File.join(File.dirname(__FILE__),'testyaml_injection.yaml')) | ||
end | ||
end | ||
|
||
def test_arrays | ||
assert_nothing_raised("Parser couldn't handle arrays in YAML") do | ||
@cfg.load_yaml_file(File.join(File.dirname(__FILE__),'testyaml_arrays.yaml')) | ||
end | ||
log = Logger['mylogger'] | ||
assert_instance_of(Array, log.outputters.first.array_param, 'Array not loaded properly from YAML') | ||
assert_equal('wilma@bar.com', log.outputters.first.array_param[2], '#{}-style parameter interpolation doesn\'t work properly in arrays') | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
log4r_config: | ||
|
||
# define all loggers ... | ||
loggers: | ||
- name : mylogger | ||
level : INFO | ||
additive : 'false' | ||
trace : 'false' | ||
outputters: | ||
- testyaml | ||
|
||
# define all outputters (incl. formatters) | ||
outputters: | ||
- type : TestYamlOutputter | ||
name : testyaml | ||
level : INFO | ||
array_param: | ||
- fred@foo.com | ||
- barney@foo.com | ||
- 'wilma@#{CUSTOM_DOMAIN}' | ||
formatter: | ||
date_pattern: '%y%m%d %H:%M:%S' | ||
pattern : '%d %l: %m ' | ||
type : PatternFormatter | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
log4r_config: | ||
|
||
# define all loggers ... | ||
loggers: | ||
- name : mylogger | ||
level : INFO | ||
additive : 'false' | ||
trace : 'false' | ||
outputters: | ||
- stderr | ||
|
||
# define all outputters (incl. formatters) | ||
outputters: | ||
- type : StderrOutputter | ||
name : stderr | ||
level : INFO | ||
crash : "'; raise Exception #" | ||
formatter: | ||
date_pattern: '%y%m%d %H:%M:%S' | ||
pattern : '%d %l: %m ' | ||
type : PatternFormatter | ||
|