• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2021-2022 Huawei Device Co., Ltd.
2# Licensed under the Apache License, Version 2.0 (the "License");
3# you may not use this file except in compliance with the License.
4# You may obtain a copy of the License at
5#
6# http://www.apache.org/licenses/LICENSE-2.0
7#
8# Unless required by applicable law or agreed to in writing, software
9# distributed under the License is distributed on an "AS IS" BASIS,
10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11# See the License for the specific language governing permissions and
12# limitations under the License.
13
14module TestRunner
15  module Reporters
16    # StringLogger is intended to keep all single test output.
17    class StringLogger
18      def initialize
19        @content = StringIO.new
20      end
21
22      def log(level, *args)
23        if @content.closed_write?
24          raise IOError,
25                "#{self.class} is closed for writing. It is possible that epilogue() is called."
26        end
27
28        @content.puts(args) if level <= $VERBOSITY
29      end
30
31      def string
32        @content.string
33      end
34
35      def close
36        @content.close
37      end
38    end
39
40    class SeparateFileLogger
41      def initialize(log_file)
42        @file = File.new(log_file, 'w')
43      end
44
45      def log(_level, *args)
46        @file.write(*args, "\n")
47      end
48
49      def string
50        ''
51      end
52
53      def close
54        @file.close
55      end
56    end
57  end
58end
59