You can put the rb to the compass-ci/lib, then the others can use it too.
On Sat, Jan 23, 2021 at 02:40:03PM +0800, Xiao Shenwei wrote:
[why] records run logs
- easy debugging
- the log will be upload to result_root
in this way, user can get message when error occurred
When you upload it then you add the change log, it's no need add in here.
Thanks, Xueliang
[how] custom format of log like this: 2021-01-22 10:11:15 +0800 INFO -- SCHED_HOST: 3000
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