-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expand logging utilities per the infinite wisdom of eholum
- Loading branch information
Showing
14 changed files
with
70 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1 @@ | ||
""" ROS 2 enabled 2D mobile robot simulator for behavior prototyping. """ | ||
|
||
import logging | ||
|
||
# Define a general PyRoboSim logger. | ||
global_logger = logging.getLogger("pyrobosim") | ||
global_logger.setLevel(logging.INFO) | ||
log_formatter = logging.Formatter("[%(name)s] %(levelname)s: %(message)s") | ||
console_handler = logging.StreamHandler() | ||
console_handler.setFormatter(log_formatter) | ||
global_logger.addHandler(console_handler) | ||
global_logger.propagate = True | ||
|
||
|
||
def get_global_logger(): | ||
""" | ||
Returns a global logger for PyRoboSim. | ||
:return: The PyRoboSim global logger instance. | ||
:rtype: :class:`logging.Logger`. | ||
""" | ||
return global_logger |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
""" | ||
Logging utilities for PyRoboSim. | ||
""" | ||
|
||
import logging | ||
|
||
|
||
def create_logger(name, level=logging.INFO): | ||
""" | ||
Defines a general logger for use with PyRoboSim. | ||
:param name: The name of the logger. | ||
:type name: str | ||
:param level: The level of the logger. | ||
:type level: int | ||
:return: A logger instance. | ||
:rtype: :class:`logging.Logger`. | ||
""" | ||
logger = logging.getLogger(name) | ||
logger.setLevel(level) | ||
|
||
# TODO: Consider configuring console vs. file logging at some point. | ||
log_formatter = logging.Formatter("[%(name)s] %(levelname)s: %(message)s") | ||
console_handler = logging.StreamHandler() | ||
console_handler.setFormatter(log_formatter) | ||
logger.addHandler(console_handler) | ||
|
||
# Needed to propagate to unit tests via the caplog fixture. | ||
logger.propagate = True | ||
|
||
return logger | ||
|
||
|
||
PYROBOSIM_GLOBAL_LOGGER = create_logger("pyrobosim") | ||
|
||
|
||
def get_global_logger(): | ||
""" | ||
Returns the global logger for PyRoboSim. | ||
:return: The PyRoboSim global logger instance. | ||
:rtype: :class:`logging.Logger`. | ||
""" | ||
return PYROBOSIM_GLOBAL_LOGGER | ||
|
||
|
||
def set_global_logger(logger): | ||
""" | ||
Sets the global PyRoboSim logger to another specified logger. | ||
:param logger: The logger to use as the new global logger. | ||
:type logger: :class:`logging.Logger` | ||
""" | ||
global PYROBOSIM_GLOBAL_LOGGER | ||
PYROBOSIM_GLOBAL_LOGGER = logger |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters