Mailinglist Archive: yast-devel (53 mails)

< Previous Next >
[yast-devel] [RFC] make Builtins.y2milestone(), y2...() obsolete?

Hi all,

another change in yast2-ruby-bindings-3.1.7 is a new
Yast::Logger module which wraps Y2Logger mentioned in the previous mail.

The module provides standard Ruby logging way [1] for writing into y2log.


Example:

module Yast
class Foo < Client
include Yast::Logger

def foo
# this will be logged into y2log using the usual y2log format

# Builtins.y2debug() replacement
log.debug "debug"
# Builtins.y2milestone() replacement
log.info "info"
# Builtins.y2error() replacement
log.error "error"
end
end
end

(See [2] for a real example)


The advantages over the Builtins.y2*() are:

- it's a standard Ruby way (used also in Rails)

- we can easily drop Builtins.y2*() in the future

- the Logger API is much more flexible (Logger can log to a different file,
STDOUT/STDERR, even a String), can be dynamically changed at run time
(set different log level, temporarily enable/disable logging, etc...)
(of course, these features do not work currently as it's just a wrapper for
y2*(),
but that could be changed easily)

- the Logger API also supports block parameter for lazy evaluation of the
message
so e.g.

log.debug { "#{(0..10000).to_a}" }

has NO performance impact if debug logging is disabled as the string is NOT
evaluated. That's nice when you log too much details or log huge data
structures.


Disadvantages:

- the y2*() functions can log different call frame or can log a complete
backtrace
(but that can be done easily in Ruby and this feature is not used much in
Yast)

- little bit different log levels, e.g. there is no direct equivalent to
y2internal(), on the other hand there is a "fatal" error level
(see [3] for the current mapping)


Problems which prevent from global change (via a script):

- percent place holders (e.g. "%1") do not work, automatic change of the
existing
code to the new logging style is not trivial

- the old logging is used in old tests, automatic replace could potentially
break some tests



So therefore I'd like to make all Builtins.y2*() functions obsolete and in new
code
use only the new logging style. And suggest changing the logging
when touching the old code (if it does not break tests).


What do you think about this proposal?


[1] http://www.ruby-doc.org/stdlib-2.1.0/libdoc/logger/rdoc/Logger.html
[2]
https://github.com/yast/yast-registration/commit/a0c852743b78ac54562e52e826854851cb8f63c8
[3]
https://github.com/yast/yast-ruby-bindings/pull/97/files#diff-c61ab27bc14ba4032691af4cf7d42f05R21

--

Ladislav Slez√°k
Appliance department / YaST Developer
Lihovarsk√° 1060/12
190 00 Prague 9 / Czech Republic
tel: +420 284 028 960
lslezak@xxxxxxxx
SUSE
--
To unsubscribe, e-mail: yast-devel+unsubscribe@xxxxxxxxxxxx
To contact the owner, e-mail: yast-devel+owner@xxxxxxxxxxxx

< Previous Next >