| 235 | | ################################################################# |
|---|
| 236 | | ### L E F T T O P O R T : |
|---|
| 237 | | ################################################################# |
|---|
| 238 | | |
|---|
| 239 | | def test_messages_should_only_be_output_once_per_outputter |
|---|
| 240 | | outputter = TestOutputter.new( "single outputter" ) |
|---|
| 241 | | |
|---|
| 242 | | for klass in [FaerieMUD, FaerieMUD::TestObject, FaerieMUD::TestObject::SubObject] |
|---|
| 243 | | FaerieMUD::Logger[ klass ].level = :debug |
|---|
| 244 | | FaerieMUD::Logger[ klass ].outputters << outputter |
|---|
| | 235 | it "only outputs a given message once even if it's registered with more than one logger" do |
|---|
| | 236 | outputter = TestOutputter.new |
|---|
| | 237 | |
|---|
| | 238 | for klass in [ TestObject, SubclassOfTestObject, GrandchildClassOfTestObject ] |
|---|
| | 239 | klass.log.level = :debug |
|---|
| | 240 | klass.log.outputters << outputter |
|---|
| 266 | | |
|---|
| 267 | | assert_include self.name.sub( /\(.*/, '' ), outputter.output |
|---|
| 268 | | end |
|---|
| 269 | | |
|---|
| 270 | | |
|---|
| 271 | | def test_parse_log_setting_should_just_return_level_if_its_a_single_word |
|---|
| 272 | | level = uri = nil |
|---|
| 273 | | |
|---|
| 274 | | assert_nothing_raised do |
|---|
| 275 | | level, uri = FaerieMUD::Logger.parse_log_setting( "debug" ) |
|---|
| 276 | | end |
|---|
| 277 | | |
|---|
| 278 | | assert_equal :debug, level |
|---|
| 279 | | assert_equal nil, uri |
|---|
| 280 | | end |
|---|
| 281 | | |
|---|
| 282 | | |
|---|
| 283 | | def test_parse_log_setting_should_return_a_uri_if_setting_has_two_words |
|---|
| 284 | | level = uri = nil |
|---|
| 285 | | |
|---|
| 286 | | assert_nothing_raised do |
|---|
| 287 | | level, uri = FaerieMUD::Logger.parse_log_setting( "info apache" ) |
|---|
| 288 | | end |
|---|
| 289 | | |
|---|
| 290 | | assert_equal :info, level |
|---|
| 291 | | assert_kind_of URI::Generic, uri |
|---|
| 292 | | end |
|---|
| 293 | | |
|---|
| 294 | | def test_parse_log_setting_should_return_a_uri_if_setting_includes_complex_uri |
|---|
| 295 | | level = uri = nil |
|---|
| 296 | | complexuri = 'dbi://www:password@localhost/www.errorlog?driver=postgresql' |
|---|
| 297 | | |
|---|
| 298 | | assert_nothing_raised do |
|---|
| 299 | | level, uri = FaerieMUD::Logger.parse_log_setting( "error #{complexuri}" ) |
|---|
| 300 | | end |
|---|
| 301 | | |
|---|
| 302 | | assert_equal :error, level |
|---|
| 303 | | assert_kind_of URI::Generic, uri |
|---|
| 304 | | end |
|---|
| 305 | | |
|---|
| 306 | | def test_configure_should_use_apache_log_outputter_if_none_specified |
|---|
| 307 | | FaerieMUD::Logger.configure( {:global => 'debug'}, nil ) |
|---|
| 308 | | |
|---|
| 309 | | assert_instance_of FaerieMUD::Logger::ApacheOutputter, |
|---|
| 310 | | FaerieMUD::Logger.global.outputters.first |
|---|
| 311 | | assert_equal :debug, FaerieMUD::Logger.global.readable_level |
|---|
| 312 | | end |
|---|
| 313 | | |
|---|
| 314 | | def test_configure_with_file_uri_should_use_fileouputter |
|---|
| 315 | | FaerieMUD::Logger.configure( {:global => 'error file:stderr'}, nil ) |
|---|
| 316 | | |
|---|
| 317 | | assert_instance_of FaerieMUD::Logger::FileOutputter, |
|---|
| 318 | | FaerieMUD::Logger.global.outputters.first |
|---|
| 319 | | assert_equal :error, FaerieMUD::Logger.global.readable_level |
|---|
| 320 | | end |
|---|
| 321 | | |
|---|
| 322 | | def test_configure_with_simple_class_name_should_prepend_arrow_namespace |
|---|
| 323 | | FaerieMUD::Logger.configure( {:applet => 'notice file:stderr'}, nil ) |
|---|
| 324 | | |
|---|
| 325 | | assert_instance_of FaerieMUD::Logger::FileOutputter, |
|---|
| 326 | | FaerieMUD::Logger[FaerieMUD::Applet].outputters.first |
|---|
| 327 | | assert_equal :notice, FaerieMUD::Logger[FaerieMUD::Applet].readable_level |
|---|
| 328 | | end |
|---|
| 329 | | |
|---|
| 330 | | def test_configure_with_full_class_name_should_create_a_logger_for_that_class |
|---|
| 331 | | FaerieMUD::Logger.configure( {:"FaerieMUD::Applet" => 'info file:stderr'}, nil ) |
|---|
| 332 | | |
|---|
| 333 | | assert_instance_of FaerieMUD::Logger::FileOutputter, |
|---|
| 334 | | FaerieMUD::Logger[FaerieMUD::Applet].outputters.first |
|---|
| 335 | | assert_equal :info, FaerieMUD::Logger[FaerieMUD::Applet].readable_level |
|---|
| 336 | | end |
|---|
| 337 | | |
|---|
| 338 | | def test_configure_with_full_class_name_should_create_a_logger_for_non_arrow_class |
|---|
| 339 | | FaerieMUD::Logger.configure( {:"String" => 'warning file:stderr'}, nil ) |
|---|
| 340 | | |
|---|
| 341 | | assert_instance_of FaerieMUD::Logger::FileOutputter, |
|---|
| 342 | | FaerieMUD::Logger[String].outputters.first |
|---|
| 343 | | assert_equal :warning, FaerieMUD::Logger[String].readable_level |
|---|
| 344 | | end |
|---|
| 345 | | |
|---|
| | 263 | |
|---|
| | 264 | outputter.messages.first.should =~ /#{__FILE__}/ |
|---|
| | 265 | end |
|---|
| | 266 | |
|---|
| | 267 | |
|---|
| | 268 | it "can parse a log configuration of just a log level" do |
|---|
| | 269 | level, uri = FaerieMUD::Logger.parse_log_setting( 'debug' ) |
|---|
| | 270 | level.should == :debug |
|---|
| | 271 | uri.should be_nil() |
|---|
| | 272 | end |
|---|
| | 273 | |
|---|
| | 274 | |
|---|
| | 275 | it "can parse a log configuration of a level and a simple (scheme-only) uri" do |
|---|
| | 276 | level, uri = FaerieMUD::Logger.parse_log_setting( 'info html' ) |
|---|
| | 277 | level.should == :info |
|---|
| | 278 | uri.should be_an_instance_of( URI::Generic ) |
|---|
| | 279 | uri.path.should == 'html' |
|---|
| | 280 | end |
|---|
| | 281 | |
|---|
| | 282 | |
|---|
| | 283 | it "can parse a log configuration that's a complex uri" do |
|---|
| | 284 | level, uri = FaerieMUD::Logger.parse_log_setting( 'notice sequel://www:password@localhost/fm.errorlog?driver=pg' ) |
|---|
| | 285 | level.should == :notice |
|---|
| | 286 | uri.should be_an_instance_of( URI::Generic ) |
|---|
| | 287 | uri.scheme.should == 'sequel' |
|---|
| | 288 | uri.user.should == 'www' |
|---|
| | 289 | uri.password.should == 'password' |
|---|
| | 290 | uri.host.should == 'localhost' |
|---|
| | 291 | end |
|---|
| | 292 | |
|---|
| | 293 | |
|---|
| | 294 | it "uses the 'file' outputter if none is specified" do |
|---|
| | 295 | FaerieMUD::Logger.configure({ :global => 'debug' }, nil ) |
|---|
| | 296 | FaerieMUD::Logger.global.outputters.should have(1).members |
|---|
| | 297 | FaerieMUD::Logger.global.outputters.first.should be_an_instance_of( FaerieMUD::Logger::FileOutputter ) |
|---|
| | 298 | end |
|---|