close the file every time after open and write it, avoid duplicate printing of logs.
Signed-off-by: Liu Yinsi liuyinsi@163.com --- user-client/maintain/walk-os-test/walk-os-iperf-test | 10 ++++++++++ 1 file changed, 10 insertions(+)
diff --git a/user-client/maintain/walk-os-test/walk-os-iperf-test b/user-client/maintain/walk-os-test/walk-os-iperf-test index d9d6bd6..7ed07c5 100755 --- a/user-client/maintain/walk-os-test/walk-os-iperf-test +++ b/user-client/maintain/walk-os-test/walk-os-iperf-test @@ -34,6 +34,16 @@ OS_MOUNT = %w[cifs initramfs].freeze
EMAIL_ADDRESS = (ENV['USER']).to_s.freeze
+def write_report(report_all) + file = File.open(LOG, 'a') + log = Logger.new(file, 'weekly') + log.formatter = proc { |_severity, datetime, _progname, msg| + "[#{datetime}]: #{msg}\n" + } + log.info(report_all) + file.close +end + def monitor(query, actions, timeout) monitor = Monitor.new monitor.overrides = query
On Fri, Nov 27, 2020 at 02:39:51PM +0800, Liu Yinsi wrote:
close the file every time after open and write it, avoid duplicate printing of logs.
Signed-off-by: Liu Yinsi liuyinsi@163.com
user-client/maintain/walk-os-test/walk-os-iperf-test | 10 ++++++++++ 1 file changed, 10 insertions(+)
diff --git a/user-client/maintain/walk-os-test/walk-os-iperf-test b/user-client/maintain/walk-os-test/walk-os-iperf-test index d9d6bd6..7ed07c5 100755 --- a/user-client/maintain/walk-os-test/walk-os-iperf-test +++ b/user-client/maintain/walk-os-test/walk-os-iperf-test @@ -34,6 +34,16 @@ OS_MOUNT = %w[cifs initramfs].freeze
EMAIL_ADDRESS = (ENV['USER']).to_s.freeze
+def write_report(report_all)
- file = File.open(LOG, 'a')
- log = Logger.new(file, 'weekly')
- log.formatter = proc { |_severity, datetime, _progname, msg|
- "[#{datetime}]: #{msg}\n"
- }
- log.info(report_all)
- file.close
Use file block, then no need to close.
Thanks, Xueliang
+end
def monitor(query, actions, timeout) monitor = Monitor.new monitor.overrides = query -- 2.23.0
On Fri, Nov 27, 2020 at 03:11:20PM +0800, Cao Xueliang wrote:
On Fri, Nov 27, 2020 at 02:39:51PM +0800, Liu Yinsi wrote:
close the file every time after open and write it, avoid duplicate printing of logs.
Signed-off-by: Liu Yinsi liuyinsi@163.com
user-client/maintain/walk-os-test/walk-os-iperf-test | 10 ++++++++++ 1 file changed, 10 insertions(+)
diff --git a/user-client/maintain/walk-os-test/walk-os-iperf-test b/user-client/maintain/walk-os-test/walk-os-iperf-test index d9d6bd6..7ed07c5 100755 --- a/user-client/maintain/walk-os-test/walk-os-iperf-test +++ b/user-client/maintain/walk-os-test/walk-os-iperf-test @@ -34,6 +34,16 @@ OS_MOUNT = %w[cifs initramfs].freeze
EMAIL_ADDRESS = (ENV['USER']).to_s.freeze
+def write_report(report_all)
- file = File.open(LOG, 'a')
- log = Logger.new(file, 'weekly')
- log.formatter = proc { |_severity, datetime, _progname, msg|
- "[#{datetime}]: #{msg}\n"
- }
- log.info(report_all)
- file.close
Use file block, then no need to close.
Thanks, Xueliang
Can you show how to use file block? An example is needed here, btw, I want to learn too.
Thanks, Xijian
On Fri, Nov 27, 2020 at 03:58:21PM +0800, Xu Xijian wrote:
On Fri, Nov 27, 2020 at 03:11:20PM +0800, Cao Xueliang wrote:
On Fri, Nov 27, 2020 at 02:39:51PM +0800, Liu Yinsi wrote:
close the file every time after open and write it, avoid duplicate printing of logs.
Signed-off-by: Liu Yinsi liuyinsi@163.com
user-client/maintain/walk-os-test/walk-os-iperf-test | 10 ++++++++++ 1 file changed, 10 insertions(+)
diff --git a/user-client/maintain/walk-os-test/walk-os-iperf-test b/user-client/maintain/walk-os-test/walk-os-iperf-test index d9d6bd6..7ed07c5 100755 --- a/user-client/maintain/walk-os-test/walk-os-iperf-test +++ b/user-client/maintain/walk-os-test/walk-os-iperf-test @@ -34,6 +34,16 @@ OS_MOUNT = %w[cifs initramfs].freeze
EMAIL_ADDRESS = (ENV['USER']).to_s.freeze
+def write_report(report_all)
- file = File.open(LOG, 'a')
- log = Logger.new(file, 'weekly')
- log.formatter = proc { |_severity, datetime, _progname, msg|
- "[#{datetime}]: #{msg}\n"
- }
- log.info(report_all)
- file.close
Use file block, then no need to close.
Thanks, Xueliang
Can you show how to use file block? An example is needed here, btw, I want to learn too.
File.open('filename', 'a') do |p_file| # do something end
Thanks, Xueliang
Thanks, Xijian
On Fri, Nov 27, 2020 at 04:07:52PM +0800, Cao Xueliang wrote:
On Fri, Nov 27, 2020 at 03:58:21PM +0800, Xu Xijian wrote:
On Fri, Nov 27, 2020 at 03:11:20PM +0800, Cao Xueliang wrote:
On Fri, Nov 27, 2020 at 02:39:51PM +0800, Liu Yinsi wrote:
close the file every time after open and write it, avoid duplicate printing of logs.
Signed-off-by: Liu Yinsi liuyinsi@163.com
user-client/maintain/walk-os-test/walk-os-iperf-test | 10 ++++++++++ 1 file changed, 10 insertions(+)
diff --git a/user-client/maintain/walk-os-test/walk-os-iperf-test b/user-client/maintain/walk-os-test/walk-os-iperf-test index d9d6bd6..7ed07c5 100755 --- a/user-client/maintain/walk-os-test/walk-os-iperf-test +++ b/user-client/maintain/walk-os-test/walk-os-iperf-test @@ -34,6 +34,16 @@ OS_MOUNT = %w[cifs initramfs].freeze
EMAIL_ADDRESS = (ENV['USER']).to_s.freeze
+def write_report(report_all)
- file = File.open(LOG, 'a')
- log = Logger.new(file, 'weekly')
- log.formatter = proc { |_severity, datetime, _progname, msg|
- "[#{datetime}]: #{msg}\n"
- }
- log.info(report_all)
- file.close
Use file block, then no need to close.
Thanks, Xueliang
Can you show how to use file block? An example is needed here, btw, I want to learn too.
File.open('filename', 'a') do |p_file| # do something end
Thanks, Xueliang
OK
Thanks, Xijian
- log = Logger.new(file, 'weekly')
- log.formatter = proc { |_severity, datetime, _progname, msg|
- "[#{datetime}]: #{msg}\n"
- }
- log.info(report_all)
- file.close
Use file block, then no need to close.
good
Thanks, Yinsi
Thanks, Xueliang
+end
def monitor(query, actions, timeout) monitor = Monitor.new monitor.overrides = query -- 2.23.0