Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Y2Logger provides a Ruby Logger for writing logs using the Yast format, can be used by external libraries for logging into y2log - added support for RSpec tests - 3.1.7
- Loading branch information
Showing
18 changed files
with
163 additions
and
24 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
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,68 @@ | ||
# encoding: utf-8 | ||
|
||
require "logger" | ||
require "singleton" | ||
|
||
require "yast/logger" | ||
|
||
module Yast | ||
|
||
# A Ruby Logger which wraps Yast.y2*() calls | ||
class Y2Logger < ::Logger | ||
include Singleton | ||
|
||
# location of the caller | ||
CALL_FRAME = 2 | ||
|
||
def add(severity, progname = nil, message = nil, &block) | ||
message = yield if block_given? | ||
|
||
case severity | ||
when DEBUG | ||
Yast.y2debug(CALL_FRAME, message) | ||
when INFO | ||
Yast.y2milestone(CALL_FRAME, message) | ||
when WARN | ||
Yast.y2warning(CALL_FRAME, message) | ||
when ERROR | ||
Yast.y2error(CALL_FRAME, message) | ||
when FATAL | ||
Yast.y2error(CALL_FRAME, message) | ||
when UNKNOWN | ||
Yast.y2internal(CALL_FRAME, message) | ||
else | ||
Yast.y2internal(CALL_FRAME, "Unknown error level #{severity}: Error: #{message}") | ||
end | ||
end | ||
|
||
def initialize(*args) | ||
# do not write to any file, the actual logging is implemented in add() | ||
super(nil) | ||
# process also debug messages but might not be logged in the end | ||
self.level = ::Logger::DEBUG | ||
end | ||
end | ||
|
||
# This module provides access to Yast specific logging | ||
# | ||
# @example Use YastLogger in an easy way | ||
# class Foo | ||
# include Yast::Logger | ||
# | ||
# def foo | ||
# # this will be logged into y2log using the usual y2log format | ||
# log.debug "debug" | ||
# log.error "error" | ||
# end | ||
# end | ||
module Logger | ||
def log | ||
Y2Logger.instance | ||
end | ||
|
||
def self.included(base) | ||
base.extend self | ||
end | ||
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
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
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
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
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
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,3 @@ | ||
$LOAD_PATH << File.dirname(__FILE__) | ||
require "test_helper" | ||
|
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,9 @@ | ||
$LOAD_PATH << File.dirname(__FILE__) | ||
require "test_helper" | ||
|
||
|
||
require 'test/unit' | ||
|
||
module Yast | ||
TestCase = Test::Unit::TestCase | ||
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
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,57 @@ | ||
#!/usr/bin/env rspec | ||
|
||
require_relative "test_helper_rspec" | ||
|
||
require "yast/y2logger" | ||
|
||
module Yast | ||
describe Y2Logger do | ||
|
||
TEST_MESSAGE = "Testing" | ||
|
||
before do | ||
@test_logger = Y2Logger.instance | ||
end | ||
|
||
it "logs debug messages via y2debug()" do | ||
Yast.should_receive(:y2debug).with(Y2Logger::CALL_FRAME, TEST_MESSAGE) | ||
@test_logger.debug TEST_MESSAGE | ||
end | ||
|
||
it "logs info messages via y2milestone()" do | ||
Yast.should_receive(:y2milestone).with(Y2Logger::CALL_FRAME, TEST_MESSAGE) | ||
@test_logger.info TEST_MESSAGE | ||
end | ||
|
||
it "logs warnings via y2warning()" do | ||
Yast.should_receive(:y2warning).with(Y2Logger::CALL_FRAME, TEST_MESSAGE) | ||
@test_logger.warn TEST_MESSAGE | ||
end | ||
|
||
it "logs errors via y2error()" do | ||
Yast.should_receive(:y2error).with(Y2Logger::CALL_FRAME, TEST_MESSAGE) | ||
@test_logger.error TEST_MESSAGE | ||
end | ||
|
||
it "logs fatal errors via y2error()" do | ||
Yast.should_receive(:y2error).with(Y2Logger::CALL_FRAME, TEST_MESSAGE) | ||
@test_logger.fatal TEST_MESSAGE | ||
end | ||
|
||
it "handles a message passed via block" do | ||
Yast.should_receive(:y2milestone).with(Y2Logger::CALL_FRAME, TEST_MESSAGE) | ||
@test_logger.info { TEST_MESSAGE } | ||
end | ||
end | ||
|
||
describe Yast::Logger do | ||
it "module adds log() method for accessing the Logger" do | ||
class Test | ||
include Yast::Logger | ||
end | ||
expect(Test.log).to be_kind_of(::Logger) | ||
expect(Test.new.log).to be_kind_of(::Logger) | ||
end | ||
end | ||
|
||
end |