diff options
author | steveblock@chromium.org <steveblock@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-07 21:12:36 +0000 |
---|---|---|
committer | steveblock@chromium.org <steveblock@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-07 21:12:36 +0000 |
commit | 5f5ceac025eddcd970426f5814e1fdae9c4d4f70 (patch) | |
tree | d6b5edbb5772e8f98b676c672c166a681d983863 /third_party/android_testrunner/logger.py | |
parent | a3d5570ff21d1a43ae7bce3a91c1274d8b30c4d7 (diff) | |
download | chromium_src-5f5ceac025eddcd970426f5814e1fdae9c4d4f70.zip chromium_src-5f5ceac025eddcd970426f5814e1fdae9c4d4f70.tar.gz chromium_src-5f5ceac025eddcd970426f5814e1fdae9c4d4f70.tar.bz2 |
Move third_party/android/testrunner to third_party/android_testrunner
The original intent was to have multiple subdirectories under
third_party/android/, but the need for these has not arisen and it potentially
adds complexity.
Also update the license checker tool to prune this directory, as the code is
used only for testing.
'tools/licenses.py scan | grep android'
See http://codereview.chromium.org/8322008.
Review URL: http://codereview.chromium.org/9622010
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@125451 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'third_party/android_testrunner/logger.py')
-rw-r--r-- | third_party/android_testrunner/logger.py | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/third_party/android_testrunner/logger.py b/third_party/android_testrunner/logger.py new file mode 100644 index 0000000..61463a1 --- /dev/null +++ b/third_party/android_testrunner/logger.py @@ -0,0 +1,96 @@ +#!/usr/bin/python2.4 +# +# +# Copyright 2007, The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Simple logging utility. Dumps log messages to stdout, and optionally, to a +log file. + +Init(path) must be called to enable logging to a file +""" + +import datetime + +_LOG_FILE = None +_verbose = False +_log_time = True + +def Init(log_file_path): + """Set the path to the log file""" + global _LOG_FILE + _LOG_FILE = log_file_path + print "Using log file: %s" % _LOG_FILE + +def GetLogFilePath(): + """Returns the path and name of the Log file""" + global _LOG_FILE + return _LOG_FILE + +def Log(new_str): + """Appends new_str to the end of _LOG_FILE and prints it to stdout. + + Args: + # new_str is a string. + new_str: 'some message to log' + """ + msg = _PrependTimeStamp(new_str) + print msg + _WriteLog(msg) + +def _WriteLog(msg): + global _LOG_FILE + if _LOG_FILE is not None: + file_handle = file(_LOG_FILE, 'a') + file_handle.write('\n' + str(msg)) + file_handle.close() + +def _PrependTimeStamp(log_string): + """Returns the log_string prepended with current timestamp """ + global _log_time + if _log_time: + return "# %s: %s" % (datetime.datetime.now().strftime("%m/%d/%y %H:%M:%S"), + log_string) + else: + # timestamp logging disabled + return log_string + +def SilentLog(new_str): + """Silently log new_str. Unless verbose mode is enabled, will log new_str + only to the log file + Args: + # new_str is a string. + new_str: 'some message to log' + """ + global _verbose + msg = _PrependTimeStamp(new_str) + if _verbose: + print msg + _WriteLog(msg) + +def SetVerbose(new_verbose=True): + """ Enable or disable verbose logging""" + global _verbose + _verbose = new_verbose + +def SetTimestampLogging(new_timestamp=True): + """ Enable or disable outputting a timestamp with each log entry""" + global _log_time + _log_time = new_timestamp + +def main(): + pass + +if __name__ == '__main__': + main() |