Python absl.logging.ERROR Examples
The following are 19
code examples of absl.logging.ERROR().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
absl.logging
, or try the search function
.
Example #1
Source File: __init__.py From abseil-py with Apache License 2.0 | 6 votes |
def set_stderrthreshold(s): """Sets the stderr threshold to the value passed in. Args: s: str|int, valid strings values are case-insensitive 'debug', 'info', 'warning', 'error', and 'fatal'; valid integer values are logging.DEBUG|INFO|WARNING|ERROR|FATAL. Raises: ValueError: Raised when s is an invalid value. """ if s in converter.ABSL_LEVELS: FLAGS.stderrthreshold = converter.ABSL_LEVELS[s] elif isinstance(s, str) and s.upper() in converter.ABSL_NAMES: FLAGS.stderrthreshold = s else: raise ValueError( 'set_stderrthreshold only accepts integer absl logging level ' 'from -3 to 1, or case-insensitive string values ' "'debug', 'info', 'warning', 'error', and 'fatal'. " 'But found "{}" ({}).'.format(s, type(s)))
Example #2
Source File: retrain.py From hub with Apache License 2.0 | 6 votes |
def logging_level_verbosity(logging_verbosity): """Converts logging_level into TensorFlow logging verbosity value. Args: logging_verbosity: String value representing logging level: 'DEBUG', 'INFO', 'WARN', 'ERROR', 'FATAL' """ name_to_level = { 'FATAL': logging.FATAL, 'ERROR': logging.ERROR, 'WARN': logging.WARN, 'INFO': logging.INFO, 'DEBUG': logging.DEBUG } try: return name_to_level[logging_verbosity] except Exception as e: raise RuntimeError('Not supported logs verbosity (%s). Use one of %s.' % (str(e), list(name_to_level)))
Example #3
Source File: converter_test.py From abseil-py with Apache License 2.0 | 6 votes |
def test_get_initial_for_level(self): self.assertEqual('F', converter.get_initial_for_level(logging.CRITICAL)) self.assertEqual('E', converter.get_initial_for_level(logging.ERROR)) self.assertEqual('W', converter.get_initial_for_level(logging.WARNING)) self.assertEqual('I', converter.get_initial_for_level(logging.INFO)) self.assertEqual('I', converter.get_initial_for_level(logging.DEBUG)) self.assertEqual('I', converter.get_initial_for_level(logging.NOTSET)) self.assertEqual('F', converter.get_initial_for_level(51)) self.assertEqual('E', converter.get_initial_for_level(49)) self.assertEqual('E', converter.get_initial_for_level(41)) self.assertEqual('W', converter.get_initial_for_level(39)) self.assertEqual('W', converter.get_initial_for_level(31)) self.assertEqual('I', converter.get_initial_for_level(29)) self.assertEqual('I', converter.get_initial_for_level(21)) self.assertEqual('I', converter.get_initial_for_level(19)) self.assertEqual('I', converter.get_initial_for_level(11)) self.assertEqual('I', converter.get_initial_for_level(9)) self.assertEqual('I', converter.get_initial_for_level(1)) self.assertEqual('I', converter.get_initial_for_level(-1))
Example #4
Source File: converter_test.py From abseil-py with Apache License 2.0 | 6 votes |
def test_standard_to_absl(self): self.assertEqual( absl_logging.DEBUG, converter.standard_to_absl(logging.DEBUG)) self.assertEqual( absl_logging.INFO, converter.standard_to_absl(logging.INFO)) self.assertEqual( absl_logging.WARN, converter.standard_to_absl(logging.WARN)) self.assertEqual( absl_logging.WARN, converter.standard_to_absl(logging.WARNING)) self.assertEqual( absl_logging.ERROR, converter.standard_to_absl(logging.ERROR)) self.assertEqual( absl_logging.FATAL, converter.standard_to_absl(logging.FATAL)) self.assertEqual( absl_logging.FATAL, converter.standard_to_absl(logging.CRITICAL)) # vlog levels. self.assertEqual(2, converter.standard_to_absl(logging.DEBUG - 1)) self.assertEqual(3, converter.standard_to_absl(logging.DEBUG - 2)) with self.assertRaises(TypeError): converter.standard_to_absl('')
Example #5
Source File: logging_test.py From abseil-py with Apache License 2.0 | 5 votes |
def test_logging_levels(self): old_level = logging.get_verbosity() logging.set_verbosity(logging.DEBUG) self.assertEquals(logging.get_verbosity(), logging.DEBUG) self.assertTrue(logging.level_debug()) self.assertTrue(logging.level_info()) self.assertTrue(logging.level_warning()) self.assertTrue(logging.level_error()) logging.set_verbosity(logging.INFO) self.assertEquals(logging.get_verbosity(), logging.INFO) self.assertFalse(logging.level_debug()) self.assertTrue(logging.level_info()) self.assertTrue(logging.level_warning()) self.assertTrue(logging.level_error()) logging.set_verbosity(logging.WARNING) self.assertEquals(logging.get_verbosity(), logging.WARNING) self.assertFalse(logging.level_debug()) self.assertFalse(logging.level_info()) self.assertTrue(logging.level_warning()) self.assertTrue(logging.level_error()) logging.set_verbosity(logging.ERROR) self.assertEquals(logging.get_verbosity(), logging.ERROR) self.assertFalse(logging.level_debug()) self.assertFalse(logging.level_info()) self.assertTrue(logging.level_error()) logging.set_verbosity(old_level)
Example #6
Source File: ncf_common.py From models with Apache License 2.0 | 5 votes |
def get_v1_distribution_strategy(params): """Returns the distribution strategy to use.""" if params["use_tpu"]: # Some of the networking libraries are quite chatty. for name in ["googleapiclient.discovery", "googleapiclient.discovery_cache", "oauth2client.transport"]: logging.getLogger(name).setLevel(logging.ERROR) tpu_cluster_resolver = tf.distribute.cluster_resolver.TPUClusterResolver( tpu=params["tpu"], zone=params["tpu_zone"], project=params["tpu_gcp_project"], coordinator_name="coordinator" ) logging.info("Issuing reset command to TPU to ensure a clean state.") tf.Session.reset(tpu_cluster_resolver.get_master()) # Estimator looks at the master it connects to for MonitoredTrainingSession # by reading the `TF_CONFIG` environment variable, and the coordinator # is used by StreamingFilesDataset. tf_config_env = { "session_master": tpu_cluster_resolver.get_master(), "eval_session_master": tpu_cluster_resolver.get_master(), "coordinator": tpu_cluster_resolver.cluster_spec() .as_dict()["coordinator"] } os.environ["TF_CONFIG"] = json.dumps(tf_config_env) distribution = tf.distribute.experimental.TPUStrategy( tpu_cluster_resolver, steps_per_run=100) else: distribution = distribution_utils.get_distribution_strategy( num_gpus=params["num_gpus"]) return distribution
Example #7
Source File: ncf_common.py From Live-feed-object-device-identification-using-Tensorflow-and-OpenCV with Apache License 2.0 | 5 votes |
def get_v1_distribution_strategy(params): """Returns the distribution strategy to use.""" if params["use_tpu"]: # Some of the networking libraries are quite chatty. for name in ["googleapiclient.discovery", "googleapiclient.discovery_cache", "oauth2client.transport"]: logging.getLogger(name).setLevel(logging.ERROR) tpu_cluster_resolver = tf.distribute.cluster_resolver.TPUClusterResolver( tpu=params["tpu"], zone=params["tpu_zone"], project=params["tpu_gcp_project"], coordinator_name="coordinator" ) logging.info("Issuing reset command to TPU to ensure a clean state.") tf.Session.reset(tpu_cluster_resolver.get_master()) # Estimator looks at the master it connects to for MonitoredTrainingSession # by reading the `TF_CONFIG` environment variable, and the coordinator # is used by StreamingFilesDataset. tf_config_env = { "session_master": tpu_cluster_resolver.get_master(), "eval_session_master": tpu_cluster_resolver.get_master(), "coordinator": tpu_cluster_resolver.cluster_spec() .as_dict()["coordinator"] } os.environ["TF_CONFIG"] = json.dumps(tf_config_env) distribution = tf.distribute.experimental.TPUStrategy( tpu_cluster_resolver, steps_per_run=100) else: distribution = distribution_utils.get_distribution_strategy( num_gpus=params["num_gpus"]) return distribution
Example #8
Source File: converter_test.py From abseil-py with Apache License 2.0 | 5 votes |
def test_string_to_standard(self): self.assertEqual(logging.DEBUG, converter.string_to_standard('debug')) self.assertEqual(logging.INFO, converter.string_to_standard('info')) self.assertEqual(logging.WARNING, converter.string_to_standard('warn')) self.assertEqual(logging.WARNING, converter.string_to_standard('warning')) self.assertEqual(logging.ERROR, converter.string_to_standard('error')) self.assertEqual(logging.CRITICAL, converter.string_to_standard('fatal')) self.assertEqual(logging.DEBUG, converter.string_to_standard('DEBUG')) self.assertEqual(logging.INFO, converter.string_to_standard('INFO')) self.assertEqual(logging.WARNING, converter.string_to_standard('WARN')) self.assertEqual(logging.WARNING, converter.string_to_standard('WARNING')) self.assertEqual(logging.ERROR, converter.string_to_standard('ERROR')) self.assertEqual(logging.CRITICAL, converter.string_to_standard('FATAL'))
Example #9
Source File: converter_test.py From abseil-py with Apache License 2.0 | 5 votes |
def test_standard_to_cpp(self): self.assertEqual(0, converter.standard_to_cpp(logging.DEBUG)) self.assertEqual(0, converter.standard_to_cpp(logging.INFO)) self.assertEqual(1, converter.standard_to_cpp(logging.WARN)) self.assertEqual(1, converter.standard_to_cpp(logging.WARNING)) self.assertEqual(2, converter.standard_to_cpp(logging.ERROR)) self.assertEqual(3, converter.standard_to_cpp(logging.FATAL)) self.assertEqual(3, converter.standard_to_cpp(logging.CRITICAL)) with self.assertRaises(TypeError): converter.standard_to_cpp('')
Example #10
Source File: converter_test.py From abseil-py with Apache License 2.0 | 5 votes |
def test_absl_to_cpp(self): self.assertEqual(0, converter.absl_to_cpp(absl_logging.DEBUG)) self.assertEqual(0, converter.absl_to_cpp(absl_logging.INFO)) self.assertEqual(1, converter.absl_to_cpp(absl_logging.WARN)) self.assertEqual(2, converter.absl_to_cpp(absl_logging.ERROR)) self.assertEqual(3, converter.absl_to_cpp(absl_logging.FATAL)) with self.assertRaises(TypeError): converter.absl_to_cpp('')
Example #11
Source File: ncf_common.py From models with Apache License 2.0 | 5 votes |
def get_v1_distribution_strategy(params): """Returns the distribution strategy to use.""" if params["use_tpu"]: # Some of the networking libraries are quite chatty. for name in ["googleapiclient.discovery", "googleapiclient.discovery_cache", "oauth2client.transport"]: logging.getLogger(name).setLevel(logging.ERROR) tpu_cluster_resolver = tf.distribute.cluster_resolver.TPUClusterResolver( tpu=params["tpu"], zone=params["tpu_zone"], project=params["tpu_gcp_project"], coordinator_name="coordinator" ) logging.info("Issuing reset command to TPU to ensure a clean state.") tf.Session.reset(tpu_cluster_resolver.get_master()) # Estimator looks at the master it connects to for MonitoredTrainingSession # by reading the `TF_CONFIG` environment variable, and the coordinator # is used by StreamingFilesDataset. tf_config_env = { "session_master": tpu_cluster_resolver.get_master(), "eval_session_master": tpu_cluster_resolver.get_master(), "coordinator": tpu_cluster_resolver.cluster_spec() .as_dict()["coordinator"] } os.environ["TF_CONFIG"] = json.dumps(tf_config_env) distribution = tf.distribute.experimental.TPUStrategy( tpu_cluster_resolver, steps_per_run=100) else: distribution = distribution_utils.get_distribution_strategy( num_gpus=params["num_gpus"]) return distribution
Example #12
Source File: logging_test.py From abseil-py with Apache License 2.0 | 5 votes |
def test_error(self): with mock.patch.object(self.logger, 'log'): self.logger.error(self.message) self.logger.log.assert_called_once_with(std_logging.ERROR, self.message)
Example #13
Source File: logging_functional_test.py From abseil-py with Apache License 2.0 | 5 votes |
def test_py_logging_verbosity_file(self, verbosity): """Tests -v/--verbosity flag with Python logging to stderr.""" v_flag = '-v=%d' % verbosity self._exec_test( _verify_ok, [['stderr', None, ''], # When using python logging, it only creates a file named INFO, # unlike C++ it also creates WARNING and ERROR files. ['absl_log_file', 'INFO', self._get_logs(verbosity)]], use_absl_log_file=True, extra_args=[v_flag])
Example #14
Source File: __init__.py From abseil-py with Apache License 2.0 | 5 votes |
def error(self, msg, *args, **kwargs): """Logs 'msg % args' with severity 'ERROR'.""" self.log(logging.ERROR, msg, *args, **kwargs)
Example #15
Source File: __init__.py From abseil-py with Apache License 2.0 | 5 votes |
def get_absl_log_prefix(record): """Returns the absl log prefix for the log record. Args: record: logging.LogRecord, the record to get prefix for. """ created_tuple = time.localtime(record.created) created_microsecond = int(record.created % 1.0 * 1e6) critical_prefix = '' level = record.levelno if _is_non_absl_fatal_record(record): # When the level is FATAL, but not logged from absl, lower the level so # it's treated as ERROR. level = logging.ERROR critical_prefix = _CRITICAL_PREFIX severity = converter.get_initial_for_level(level) return '%c%02d%02d %02d:%02d:%02d.%06d %5d %s:%d] %s' % ( severity, created_tuple.tm_mon, created_tuple.tm_mday, created_tuple.tm_hour, created_tuple.tm_min, created_tuple.tm_sec, created_microsecond, _get_thread_id(), record.filename, record.lineno, critical_prefix)
Example #16
Source File: __init__.py From abseil-py with Apache License 2.0 | 5 votes |
def log(level, msg, *args, **kwargs): """Logs 'msg % args' at absl logging level 'level'. If no args are given just print msg, ignoring any interpolation specifiers. Args: level: int, the absl logging level at which to log the message (logging.DEBUG|INFO|WARNING|ERROR|FATAL). While some C++ verbose logging level constants are also supported, callers should prefer explicit logging.vlog() calls for such purpose. msg: str, the message to be logged. *args: The args to be substituted into the msg. **kwargs: May contain exc_info to add exception traceback to message. """ if level > converter.ABSL_DEBUG: # Even though this function supports level that is greater than 1, users # should use logging.vlog instead for such cases. # Treat this as vlog, 1 is equivalent to DEBUG. standard_level = converter.STANDARD_DEBUG - (level - 1) else: if level < converter.ABSL_FATAL: level = converter.ABSL_FATAL standard_level = converter.absl_to_standard(level) # Match standard logging's behavior. Before use_absl_handler() and # logging is configured, there is no handler attached on _absl_logger nor # logging.root. So logs go no where. if not logging.root.handlers: logging.basicConfig() _absl_logger.log(standard_level, msg, *args, **kwargs)
Example #17
Source File: __init__.py From abseil-py with Apache License 2.0 | 5 votes |
def error(msg, *args, **kwargs): """Logs an error message.""" log(ERROR, msg, *args, **kwargs)
Example #18
Source File: layers.py From mead-baseline with Apache License 2.0 | 5 votes |
def set_tf_log_level(ll): # 0 | DEBUG | [Default] Print all messages # 1 | INFO | Filter out INFO messages # 2 | WARNING | Filter out INFO & WARNING messages # 3 | ERROR | Filter out all messages import os TF_VERSION = get_version(tf) if TF_VERSION < 2: import tensorflow.compat.v1.logging as tf_logging else: from absl import logging as tf_logging tf_ll = tf_logging.WARN tf_cpp_ll = 1 ll = ll.lower() if ll == "debug": tf_ll = tf_logging.DEBUG tf_cpp_ll = 0 if ll == "info": tf_cpp_ll = 0 tf_ll = tf_logging.INFO if ll == "error": tf_ll = tf_logging.ERROR tf_cpp_ll = 2 tf_logging.set_verbosity(tf_ll) os.environ["TF_CPP_MIN_LOG_LEVEL"] = f"{tf_cpp_ll}"
Example #19
Source File: logging_test.py From abseil-py with Apache License 2.0 | 4 votes |
def test_set_verbosity_strings(self): old_level = logging.get_verbosity() # Lowercase names. logging.set_verbosity('debug') self.assertEquals(logging.get_verbosity(), logging.DEBUG) logging.set_verbosity('info') self.assertEquals(logging.get_verbosity(), logging.INFO) logging.set_verbosity('warning') self.assertEquals(logging.get_verbosity(), logging.WARNING) logging.set_verbosity('warn') self.assertEquals(logging.get_verbosity(), logging.WARNING) logging.set_verbosity('error') self.assertEquals(logging.get_verbosity(), logging.ERROR) logging.set_verbosity('fatal') # Uppercase names. self.assertEquals(logging.get_verbosity(), logging.FATAL) logging.set_verbosity('DEBUG') self.assertEquals(logging.get_verbosity(), logging.DEBUG) logging.set_verbosity('INFO') self.assertEquals(logging.get_verbosity(), logging.INFO) logging.set_verbosity('WARNING') self.assertEquals(logging.get_verbosity(), logging.WARNING) logging.set_verbosity('WARN') self.assertEquals(logging.get_verbosity(), logging.WARNING) logging.set_verbosity('ERROR') self.assertEquals(logging.get_verbosity(), logging.ERROR) logging.set_verbosity('FATAL') self.assertEquals(logging.get_verbosity(), logging.FATAL) # Integers as strings. logging.set_verbosity(str(logging.DEBUG)) self.assertEquals(logging.get_verbosity(), logging.DEBUG) logging.set_verbosity(str(logging.INFO)) self.assertEquals(logging.get_verbosity(), logging.INFO) logging.set_verbosity(str(logging.WARNING)) self.assertEquals(logging.get_verbosity(), logging.WARNING) logging.set_verbosity(str(logging.ERROR)) self.assertEquals(logging.get_verbosity(), logging.ERROR) logging.set_verbosity(str(logging.FATAL)) self.assertEquals(logging.get_verbosity(), logging.FATAL) logging.set_verbosity(old_level)