Skip to content

Commit ec3f23b

Browse files
authored
Merge pull request #661 from seleniumbase/improve-basic-logging
Improve basic logging with date, time, and time-zone info
2 parents eec27ba + 3c24d77 commit ec3f23b

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

seleniumbase/core/log_helper.py

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import codecs
2+
import datetime
23
import os
34
import shutil
45
import sys
@@ -33,10 +34,34 @@ def log_test_failure_data(test, test_logpath, driver, browser, url=None):
3334
last_page = url
3435
else:
3536
last_page = get_last_page(driver)
37+
timestamp = str(int(time.time())) + " (Unix Timestamp)"
38+
now = datetime.datetime.now()
39+
utc_offset = -time.timezone / 3600.0
40+
utc_str = "UTC+0"
41+
if utc_offset > 0:
42+
utc_str = "UTC+%s" % utc_offset
43+
elif utc_offset < 0:
44+
utc_str = "UTC%s" % utc_offset
45+
utc_str = utc_str.replace('.5', '.3').replace('.', ':') + "0"
46+
time_zone = '(' + '/'.join(time.tzname) + ', ' + utc_str + ')'
47+
# Use [Day-of-Week, Month Day, Year] format when time zone < GMT/UTC-3
48+
the_date = now.strftime("%A, %B %d, %Y").replace(' 0', ' ')
49+
if utc_offset >= -3:
50+
# Use [Day-of-Week, Day Month Year] format when time zone >= GMT/UTC-3
51+
the_date = now.strftime("%A, %d %B %Y").replace(' 0', ' ')
52+
the_time = now.strftime("%I:%M:%S %p ") + time_zone
53+
if the_time.startswith("0"):
54+
the_time = the_time[1:]
55+
test_id = get_test_id(test)
3656
data_to_save = []
57+
data_to_save.append("%s" % test_id)
58+
data_to_save.append("----------------------------------------------------")
3759
data_to_save.append("Last Page: %s" % last_page)
3860
data_to_save.append(" Browser: %s" % browser)
39-
data_to_save.append("Timestamp: %s" % int(time.time()))
61+
data_to_save.append("Timestamp: %s" % timestamp)
62+
data_to_save.append(" Date: %s" % the_date)
63+
data_to_save.append(" Time: %s" % the_time)
64+
data_to_save.append("----------------------------------------------------")
4065
if sys.version_info[0] >= 3 and hasattr(test, '_outcome') and (
4166
hasattr(test._outcome, 'errors') and test._outcome.errors):
4267
try:
@@ -93,6 +118,16 @@ def log_page_source(test_logpath, driver, source=None):
93118
html_file.close()
94119

95120

121+
def get_test_id(test):
122+
test_id = "%s.%s.%s" % (
123+
test.__class__.__module__,
124+
test.__class__.__name__,
125+
test._testMethodName)
126+
if test._sb_test_identifier and len(str(test._sb_test_identifier)) > 6:
127+
test_id = test._sb_test_identifier
128+
return test_id
129+
130+
96131
def get_last_page(driver):
97132
try:
98133
last_page = driver.current_url

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454

5555
setup(
5656
name='seleniumbase',
57-
version='1.46.10',
57+
version='1.46.11',
5858
description='Web Automation and Test Framework - https://seleniumbase.io',
5959
long_description=long_description,
6060
long_description_content_type='text/markdown',

0 commit comments

Comments
 (0)