[why] records run logs 1. easy debugging 2. the log will be upload to result_root in the fulture
[how] custom format of log like this: 2021-01-22 10:11:15 +0800 INFO -- SCHED_HOST: 3000
in this way, user can perceived message when error occurred
Signed-off-by: Xiao Shenwei xiaoshenwei96@163.com --- providers/libvirt/lib/mylog.rb | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 providers/libvirt/lib/mylog.rb
diff --git a/providers/libvirt/lib/mylog.rb b/providers/libvirt/lib/mylog.rb new file mode 100644 index 0000000..38f8c98 --- /dev/null +++ b/providers/libvirt/lib/mylog.rb @@ -0,0 +1,29 @@ +# SPDX-License-Identifier: MulanPSL-2.0+ +# Copyright (c) 2020 Huawei Technologies Co., Ltd. All rights reserved. +# frozen_string_literal: true + +require 'logger' + +# define a logger format +class Mylog < Logger + def initialize(filename) + File.delete(filename) if File.exist?(filename) + super(filename) + format + end + + private + + def format + self.datetime_format = '%Y-%m-%d %H:%M:%s' + self.formatter = proc do |severity, datetime, _progname, msg| + msg = if msg.is_a? Exception + ["#{msg.backtrace.first}: #{msg.message.split("\n").first} (#{msg.class.name})", + msg.backtrace[1..-1].map { |m| "\tfrom #{m}" }].flatten + else + msg.to_s.split("\n") + end + msg.map { |m| "#{datetime} #{severity} -- #{m}\n" }.join + end + end +end
spell: bvirt -> libvirt
Thanks, RenWen
On Sat, Jan 23, 2021 at 11:48:13AM +0800, Xiao Shenwei wrote:
[why] records run logs
- easy debugging
- the log will be upload to result_root in the fulture
[how] custom format of log like this: 2021-01-22 10:11:15 +0800 INFO -- SCHED_HOST: 3000
in this way, user can perceived message when error occurred
Signed-off-by: Xiao Shenwei xiaoshenwei96@163.com
providers/libvirt/lib/mylog.rb | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 providers/libvirt/lib/mylog.rb
diff --git a/providers/libvirt/lib/mylog.rb b/providers/libvirt/lib/mylog.rb new file mode 100644 index 0000000..38f8c98 --- /dev/null +++ b/providers/libvirt/lib/mylog.rb @@ -0,0 +1,29 @@ +# SPDX-License-Identifier: MulanPSL-2.0+ +# Copyright (c) 2020 Huawei Technologies Co., Ltd. All rights reserved. +# frozen_string_literal: true
+require 'logger'
+# define a logger format +class Mylog < Logger
- def initialize(filename)
- File.delete(filename) if File.exist?(filename)
- super(filename)
- format
- end
- private
- def format
- self.datetime_format = '%Y-%m-%d %H:%M:%s'
- self.formatter = proc do |severity, datetime, _progname, msg|
msg = if msg.is_a? Exception
["#{msg.backtrace.first}: #{msg.message.split("\n").first} (#{msg.class.name})",
msg.backtrace[1..-1].map { |m| "\tfrom #{m}" }].flatten
else
msg.to_s.split("\n")
end
msg.map { |m| "#{datetime} #{severity} -- #{m}\n" }.join
- end
- end
+end
2.23.0
On Sat, Jan 23, 2021 at 11:56:33AM +0800, Ren Wen wrote:
spell: bvirt -> libvirt
ok,
Thanks, Shenwei
Thanks, RenWen
On Sat, Jan 23, 2021 at 11:48:13AM +0800, Xiao Shenwei wrote:
[why] records run logs
- easy debugging
- the log will be upload to result_root in the fulture
[how] custom format of log like this: 2021-01-22 10:11:15 +0800 INFO -- SCHED_HOST: 3000
in this way, user can perceived message when error occurred
Signed-off-by: Xiao Shenwei xiaoshenwei96@163.com
providers/libvirt/lib/mylog.rb | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 providers/libvirt/lib/mylog.rb
diff --git a/providers/libvirt/lib/mylog.rb b/providers/libvirt/lib/mylog.rb new file mode 100644 index 0000000..38f8c98 --- /dev/null +++ b/providers/libvirt/lib/mylog.rb @@ -0,0 +1,29 @@ +# SPDX-License-Identifier: MulanPSL-2.0+ +# Copyright (c) 2020 Huawei Technologies Co., Ltd. All rights reserved. +# frozen_string_literal: true
+require 'logger'
+# define a logger format +class Mylog < Logger
- def initialize(filename)
- File.delete(filename) if File.exist?(filename)
- super(filename)
- format
- end
- private
- def format
- self.datetime_format = '%Y-%m-%d %H:%M:%s'
- self.formatter = proc do |severity, datetime, _progname, msg|
msg = if msg.is_a? Exception
["#{msg.backtrace.first}: #{msg.message.split("\n").first} (#{msg.class.name})",
msg.backtrace[1..-1].map { |m| "\tfrom #{m}" }].flatten
else
msg.to_s.split("\n")
end
msg.map { |m| "#{datetime} #{severity} -- #{m}\n" }.join
- end
- end
+end
2.23.0