diff options
author | Abseil Team <absl-team@google.com> | 2018-07-18 13:45:35 -0700 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-07-18 15:10:13 -0700 |
commit | 607faa20a3b4c8c09ef8664d3615aca3f0dd9aae (patch) | |
tree | efde35b80dceaae56225a8bcec9c569a6bad7f3b /absl/logging/tests | |
parent | 3d7f8688e4210900caa702379d0d118b0b84ea51 (diff) | |
download | absl-py-607faa20a3b4c8c09ef8664d3615aca3f0dd9aae.tar.gz |
Create `log_every_n_seconds` - log conditionally based on last log time.
Related to `log_every_n`, the logging framework maintains some state per call
site with the last time logging was done. The call to `log_every_n_seconds`
will only actually log if `n_seconds` have elapsed since the last call that
logged (or this is the first call from the given site).
PiperOrigin-RevId: 205129844
Diffstat (limited to 'absl/logging/tests')
-rwxr-xr-x | absl/logging/tests/logging_functional_test.py | 10 | ||||
-rwxr-xr-x | absl/logging/tests/logging_functional_test_helper.py | 9 |
2 files changed, 19 insertions, 0 deletions
diff --git a/absl/logging/tests/logging_functional_test.py b/absl/logging/tests/logging_functional_test.py index 5fb4e90..b809bb4 100755 --- a/absl/logging/tests/logging_functional_test.py +++ b/absl/logging/tests/logging_functional_test.py @@ -59,6 +59,11 @@ I1231 23:59:59.000000 12345 logging_functional_test_helper.py:65] This line is l I1231 23:59:59.000000 12345 logging_functional_test_helper.py:70] Interesting Stuff\0 I1231 23:59:59.000000 12345 logging_functional_test_helper.py:71] Interesting Stuff with Arguments: 42 I1231 23:59:59.000000 12345 logging_functional_test_helper.py:73] Interesting Stuff with Dictionary +I1231 23:59:59.000000 12345 logging_functional_test_helper.py:123] This should appear 5 times. +I1231 23:59:59.000000 12345 logging_functional_test_helper.py:123] This should appear 5 times. +I1231 23:59:59.000000 12345 logging_functional_test_helper.py:123] This should appear 5 times. +I1231 23:59:59.000000 12345 logging_functional_test_helper.py:123] This should appear 5 times. +I1231 23:59:59.000000 12345 logging_functional_test_helper.py:123] This should appear 5 times. I1231 23:59:59.000000 12345 logging_functional_test_helper.py:76] Info first 1 of 2 I1231 23:59:59.000000 12345 logging_functional_test_helper.py:77] Info 1 (every 3) I1231 23:59:59.000000 12345 logging_functional_test_helper.py:76] Info first 2 of 2 @@ -71,6 +76,11 @@ This line is log level 0 Interesting Stuff\0 Interesting Stuff with Arguments: 42 Interesting Stuff with Dictionary +This should appear 5 times. +This should appear 5 times. +This should appear 5 times. +This should appear 5 times. +This should appear 5 times. Info first 1 of 2 Info 1 (every 3) Info first 2 of 2 diff --git a/absl/logging/tests/logging_functional_test_helper.py b/absl/logging/tests/logging_functional_test_helper.py index 43a692f..93db54d 100755 --- a/absl/logging/tests/logging_functional_test_helper.py +++ b/absl/logging/tests/logging_functional_test_helper.py @@ -23,10 +23,12 @@ import os import sys import threading import time +import timeit from absl import app from absl import flags from absl import logging +import mock from six.moves import xrange # pylint: disable=redefined-builtin FLAGS = flags.FLAGS @@ -60,6 +62,13 @@ def _test_do_logging(): logging.info('%(a)s Stuff with %(b)s', {'a': 'Interesting', 'b': 'Dictionary'}) + with mock.patch.object(timeit, 'default_timer') as mock_timer: + mock_timer.return_value = 0 + while timeit.default_timer() < 9: + logging.log_every_n_seconds(logging.INFO, 'This should appear 5 times.', + 2) + mock_timer.return_value = mock_timer() + .2 + for i in xrange(1, 5): logging.log_first_n(logging.INFO, 'Info first %d of %d', 2, i, 2) logging.log_every_n(logging.INFO, 'Info %d (every %d)', 3, i, 3) |