OLD | NEW |
1 # Copyright (c) 2009, Google Inc. All rights reserved. | 1 # Copyright (c) 2009, Google Inc. All rights reserved. |
2 # Copyright (c) 2009 Apple Inc. All rights reserved. | 2 # Copyright (c) 2009 Apple Inc. All rights reserved. |
3 # | 3 # |
4 # Redistribution and use in source and binary forms, with or without | 4 # Redistribution and use in source and binary forms, with or without |
5 # modification, are permitted provided that the following conditions are | 5 # modification, are permitted provided that the following conditions are |
6 # met: | 6 # met: |
7 # | 7 # |
8 # * Redistributions of source code must retain the above copyright | 8 # * Redistributions of source code must retain the above copyright |
9 # notice, this list of conditions and the following disclaimer. | 9 # notice, this list of conditions and the following disclaimer. |
10 # * Redistributions in binary form must reproduce the above | 10 # * Redistributions in binary form must reproduce the above |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 self._tee_outputs_to_files(self._files_for_output) | 57 self._tee_outputs_to_files(self._files_for_output) |
58 return log_file | 58 return log_file |
59 | 59 |
60 def remove_log(self, log_file): | 60 def remove_log(self, log_file): |
61 self._files_for_output.remove(log_file) | 61 self._files_for_output.remove(log_file) |
62 self._tee_outputs_to_files(self._files_for_output) | 62 self._tee_outputs_to_files(self._files_for_output) |
63 log_file.close() | 63 log_file.close() |
64 | 64 |
65 @staticmethod | 65 @staticmethod |
66 def _open_log_file(log_path): | 66 def _open_log_file(log_path): |
67 (log_directory, log_name) = os.path.split(log_path) | 67 log_directory, _ = os.path.split(log_path) |
68 if log_directory and not os.path.exists(log_directory): | 68 if log_directory and not os.path.exists(log_directory): |
69 os.makedirs(log_directory) | 69 os.makedirs(log_directory) |
70 return codecs.open(log_path, "a+", "utf-8") | 70 return codecs.open(log_path, "a+", "utf-8") |
71 | 71 |
72 def _tee_outputs_to_files(self, files): | 72 def _tee_outputs_to_files(self, files): |
73 if not self._original_stdout: | 73 if not self._original_stdout: |
74 self._original_stdout = sys.stdout | 74 self._original_stdout = sys.stdout |
75 self._original_stderr = sys.stderr | 75 self._original_stderr = sys.stderr |
76 if files and len(files): | 76 if files and len(files): |
77 sys.stdout = Tee(self._original_stdout, *files) | 77 sys.stdout = Tee(self._original_stdout, *files) |
78 sys.stderr = Tee(self._original_stderr, *files) | 78 sys.stderr = Tee(self._original_stderr, *files) |
79 else: | 79 else: |
80 sys.stdout = self._original_stdout | 80 sys.stdout = self._original_stdout |
81 sys.stderr = self._original_stderr | 81 sys.stderr = self._original_stderr |
OLD | NEW |