Public API¶
UI¶
Within UI process, call both:
LoggingState
ui_yaml_curated or setup_ui_other
worker process¶
Step 1¶
Within worker entrypoint call either:
worker_yaml_curated or setup_worker_other
Then pass str_yaml to the worker process
Step 2¶
Within worker process call
setup_logging_yaml
Constants¶
LoggingConfigCategory [constant docs]
tl;dr; ^^ won’t need this ^^
Process categories Enum. Iterate over the Enum values, using class method, categories.
strict_logging public methods are convenience functions for class, strict_logging.logging_api.LoggingConfigYaml. If LoggingConfigYaml used directly, choose one of the LoggingConfigCategory values to pass as param, category.
Values: LoggingConfigCategory.UI or LoggingConfigCategory.WORKER
Corresponds to ‘app’ and ‘worker’
Types¶
LoggingYamlType [type docs]
tl;dr; ^^ won’t need this ^^
Useful only during strict type checking. class LoggingConfigYaml implements LoggingYamlType interface and is a direct subclass
e.g. type[LoggingYamlType]
Exceptions¶
LoggingStrictError
logging_strict catch all Exception. Base type of other exceptions. Implements ValueError
Provided just for completeness. Not intended for use
LoggingStrictPackageNameRequired
ep requires package name
Corresponding exit code – 6
LoggingStrictPackageStartFolderNameRequired
ep requires package start folder name
In logging-strict this is configs. Normally its data. But it can be anything
Corresponding exit code – 7
LoggingStrictProcessCategoryRequired
Applicable only during extract or setup, not during validation
Category required. Either:
LoggingConfigCategory.UI.value or LoggingConfigCategory.WORKER.value
Which corresponds to “app” or “worker”
LoggingStrictGenreRequired
Applicable only during extract or setup, not during validation
UI framework terse name or worker implementation characteristic
e.g. textual, rich, mp or mq
- class logging_strict.LoggingConfigCategory(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)¶
logging.config yaml process categories
Public API
from logging_strict import LoggingConfigCategory
- UI = 'app'¶
- WORKER = 'worker'¶
- __module__ = 'logging_strict.constants'¶
- classmethod categories()¶
Get Enum items’ value
- Returns:
In this case, Enum values holds str
- Return type:
- class logging_strict.LoggingState¶
Singleton to hold the current logging state. To know whether or not, run by app or from cli
logging is redirected to
If run from app –>
textual.logging.TextualHandlerIf run from cli –>
logging.StreamHandler
Knowing the logging mode (or state), first step towards restoring logging mode
Class variables
- Variables:
_instance – Default
None. Holds Singleton instance_lock – Thread lock for Singleton
- __annotations__ = {'_instance': "'LoggingState' | None"}¶
- __dict__ = mappingproxy({'__module__': 'logging_strict.logging_api', '__firstlineno__': 996, '__annotations__': {'_instance': "'LoggingState' | None"}, '__doc__': 'Singleton to hold the current logging state.\nTo know whether or not, run by app or from cli\n\nlogging is redirected to\n\n- If run from app --> :py:exc:`textual.logging.TextualHandler`\n\n- If run from cli --> :py:class:`logging.StreamHandler`\n\nKnowing the logging mode (or state), first step towards restoring logging mode\n\nClass variables\n\n:cvar _instance: Default ``None``. Holds Singleton instance\n:type _instance: ``"LoggingState"`` | None\n:cvar _lock: Thread lock for Singleton\n:type _lock: threading.RLock\n\n.. seealso::\n\n See :py:mod:`textual.logging`\n\n Thread safe Singleton\n `[blog post] <https://medium.com/analytics-vidhya/how-to-create-a-thread-safe-singleton-class-in-python-822e1170a7f6>`_\n\n', '_instance': None, '_lock': <unlocked _thread.RLock object owner=0 count=0>, '__new__': <staticmethod(<function LoggingState.__new__>)>, 'reset': <classmethod(<function LoggingState.reset>)>, 'is_state_app': <property object>, '__static_attributes__': ('_state',), '__dict__': <attribute '__dict__' of 'LoggingState' objects>, '__weakref__': <attribute '__weakref__' of 'LoggingState' objects>})¶
- __firstlineno__ = 996¶
- __module__ = 'logging_strict.logging_api'¶
- static __new__(cls)¶
- Returns:
Singleton instance
- Return type:
"LoggingState"
- __static_attributes__ = ('_state',)¶
- __weakref__¶
list of weak references to the object
- property is_state_app¶
Get logging state
- Returns:
Trueif app logging state otherwiseFalse- Return type:
bool | None
- classmethod reset()¶
A cheat to reset the Singleton state. Use only during testing
- exception logging_strict.LoggingStrictError(msg)¶
Catchall back exception
- Variables:
msg (str) – The error message
- __annotations__ = {}¶
- __firstlineno__ = 41¶
- __init__(msg)¶
Exception class constructor
- __module__ = 'logging_strict.exceptions'¶
- __static_attributes__ = ()¶
- __weakref__¶
list of weak references to the object
- exception logging_strict.LoggingStrictGenreRequired(msg)¶
Genre is required
- Variables:
msg (str) – The error message
- __annotations__ = {}¶
- __firstlineno__ = 89¶
- __init__(msg)¶
Exception class constructor
- __module__ = 'logging_strict.exceptions'¶
- __static_attributes__ = ()¶
- exception logging_strict.LoggingStrictPackageNameRequired(msg)¶
In entrypoint, package name is required
- Variables:
msg (str) – The error message
- __annotations__ = {}¶
- __firstlineno__ = 53¶
- __init__(msg)¶
Exception class constructor
- __module__ = 'logging_strict.exceptions'¶
- __static_attributes__ = ()¶
- exception logging_strict.LoggingStrictPackageStartFolderNameRequired(msg)¶
In entrypoint, package start data folder name is required
- Variables:
msg (str) – The error message
- __annotations__ = {}¶
- __firstlineno__ = 65¶
- __init__(msg)¶
Exception class constructor
- __module__ = 'logging_strict.exceptions'¶
- __static_attributes__ = ()¶
- exception logging_strict.LoggingStrictProcessCategoryRequired(msg)¶
Category is required
- Variables:
msg (str) – The error message
- __annotations__ = {}¶
- __firstlineno__ = 77¶
- __init__(msg)¶
Exception class constructor
- __module__ = 'logging_strict.exceptions'¶
- __static_attributes__ = ()¶
- class logging_strict.LoggingYamlType¶
ABC for LoggingYaml implementations
- __abstractmethods__ = frozenset({'dest_folder', 'extract', 'file_name', 'file_stem', 'package'})¶
- __dict__ = mappingproxy({'__module__': 'logging_strict.logging_yaml_abc', '__firstlineno__': 263, '__doc__': 'ABC for LoggingYaml implementations', 'get_version': <staticmethod(<function LoggingYamlType.get_version>)>, 'pattern': <classmethod(<function LoggingYamlType.pattern>)>, 'iter_yamls': <function LoggingYamlType.iter_yamls>, '__subclasshook__': <classmethod(<function LoggingYamlType.__subclasshook__>)>, 'file_stem': <property object>, 'file_name': <property object>, 'package': <property object>, 'dest_folder': <property object>, 'extract': <function LoggingYamlType.extract>, 'as_str': <function LoggingYamlType.as_str>, 'setup': <function LoggingYamlType.setup>, '__static_attributes__': (), '__dict__': <attribute '__dict__' of 'LoggingYamlType' objects>, '__weakref__': <attribute '__weakref__' of 'LoggingYamlType' objects>, '__abstractmethods__': frozenset({'package', 'extract', 'file_stem', 'file_name', 'dest_folder'}), '_abc_impl': <_abc._abc_data object>, '__annotations__': {}})¶
- __firstlineno__ = 263¶
- __module__ = 'logging_strict.logging_yaml_abc'¶
- __static_attributes__ = ()¶
- classmethod __subclasshook__(C)¶
A class wanting to be
LoggingYamlType, minimally requires:Properties:
file_stem
file_name
package
dest_folder
Methods:
extract
as_str – get for free
setup – get for free
Then register itself
LoggingYamlType.register(AnotherDatumClass)or subclassLoggingYamlType- Parameters:
C¶ (Any) – Class to test whether implements this interface or is a subclass
- Returns:
TrueimplementsLoggingYamlTypeinterface or is a subclass.Falsenot aLoggingYamlType- Return type:
- __weakref__¶
list of weak references to the object
- as_str()¶
Read the YAML config file, raise an error if not there or invalid
The yaml files must have already been extracted from a package
- Returns:
YAML str. Pass this to each worker
- Return type:
- Raises:
strictyaml.exceptions.YAMLValidationError– Invalid. Validation against logging.config schema failedFileNotFoundError– Could not find logging config YAML fileLoggingStrictGenreRequired– Genre required to get file name
- abstract property dest_folder¶
logging.configyaml file export destination folder- Returns:
Destination folder. XDG user data dir, on linux,
$HOME/.local/share/[app name]- Return type:
- abstract extract(path_relative_package_dir='')¶
Extract
logging.configyaml files to xdg user data dir- Parameters:
path_relative_package_dir¶ (pathlib.Path | str | None) – Default empty string. Relative to the package base data folder, provide a relative path or str to narrow search results
- Returns:
Destination path of extracted/exported
logging.configyaml file(s)- Return type:
- abstract property file_name¶
Get full file name. Includes stem and suffixes
- Returns:
file name
- Return type:
- static get_version(val)¶
Get a particular version of a
logging.configyaml file
- iter_yamls(path_dir)¶
Conducts a recursive search thru the folder tree starting from package base data folder, further narrow search by relative (to package base data folder) path,
logging_strict.logging_yaml_abc.LoggingYamlType.iter_yamls.params.path_dirIterator of absolute path of search results
- Parameters:
path_dir¶ (pathlib.Path | None) – Absolute path to a folder
- Returns:
Within folder tree, iterator of yaml
Trueif at least one yaml file exists in folder otherwiseFalse- Return type:
- classmethod pattern(category=None, genre=None, flavor=None, version=None)¶
Search pattern. Can’t distinguish latest version.
Each paramater narrows down search results.
version applies to:
genre
or
genre and flavor
- Parameters:
genre¶ (str | None) – If UI: “textual” or “rich”. If worker: “stream”. Then can have a library of yaml files that can be used with a particular UI framework or worker type
Unique identifier name given to a particular
logging.configyaml. This name is slugified. Meaning period and underscores converted to hyphensFlavor is a very terse description, for a
logging_strict.logging_yaml_abc.LoggingYamlType.pattern.params.genre, how this yaml differs from others. If completely generic, call itgeneric. If different handlers or formatters or filters are used, what is the yaml’s purpose?version¶ (Any | None) – Default “1”. Version of this particular
logging_strict.logging_yaml_abc.LoggingYamlType.pattern.params.category. Not the version of the yaml spec. Don’t confuse the two.
- Returns:
Pattern used with
glob.glob()to find files- Return type:
- setup(str_yaml, package_name=None)¶
Only called by app, not worker. For worker, is a 2 step process, not 1.
A
multiprocessing.pool.Poolworker, needs to be feed the contents of thelogging.configYAML filexdg user data folder:
$HOME/.local/share/[app name]- Parameters:
str_yaml¶ (str) –
logging.configyaml strpackage_name¶ – In logger dict, instead of the default package name, set a package name. Always desirable.
- Type:
str | None
- logging_strict.setup_logging_yaml(path_yaml, package_name=None)¶
Loads
logging.configconfiguration.Can pass in a path or a the YAML str
- Parameters:
path_yaml¶ (Any) –
logging.configYAML file pathpackage_name¶ (str | None) – Set logger to the intended package name. Default None which leaves as-is
- Raises:
strictyaml.YAMLValidationError– Invalid. Validation against logging.config schema failed
- logging_strict.setup_ui_other(package_name, package_data_folder_start, genre, flavor, version_no='1', package_start_relative_folder='', logger_package_name=None)¶
Before creating an App instance, seemlessly extracts
logging.configyaml file for app, but not worker(s)- Parameters:
package_name¶ (str) – Package name containing
logging.configyaml filepackage_data_folder_start¶ (str) – Package base data folder name. Not a relative path. This is the fallback search folder. Use package_start_relative_folder to further narrow the search
genre¶ (str) – UI framework or worker implementation characteristic. E.g. textual, rich, mp, or mq
version_no¶ (Any | None) – Default “1”. Applies to genre or genre & flavor
package_start_relative_folder¶ (str | None) –
Default empty string.Relative to package_data_folder_start.Relative path to further narrow down which folder contains thelogging.configyaml file.Needed when multiple folders containlogging.configyaml filewith same file namelogger_package_name¶ (str | None) – Default None. Update the dict to set a more appropriate logger package name. Will always want to do this
- Returns:
relative path to validated logging config YAML file and the yaml str
- Return type:
- Raises:
ImportError– package not installed in venvFileNotFoundError– yaml file not found within packagestrictyaml.exceptions.YAMLValidationError– yaml file validation failedAssertionError– Expecting one yaml file, many foundlogging_strict.LoggingStrictPackageNameRequired– Which package are the logging.config yaml in?logging_strict.LoggingStrictPackageStartFolderNameRequired– Within the provided package, the package base data folder name
- logging_strict.setup_worker_other(package_name, package_data_folder_start, genre, flavor, version_no='1', package_start_relative_folder='', logger_package_name=None)¶
worker_yaml_curated grabs the logging.config yaml from logging-strict. Use this if located in another package
Process 2nd step is calling:
setup_logging_yaml()- Parameters:
package_name¶ (str) – If logging_strict, use method worker_yaml_curated instead. Otherwise package name which contains the logging.config yaml files
package_data_folder_start¶ (str) – Within
package_name, base data folder name. Not a relative path. Does not assumedatagenre¶ (str) – Default “mp”. If UI: “textual” or “rich”. If worker: “mp”. Then can have a library of yaml files that can be used with a particular UI framework or worker type
Default “asz”. Unique identifier name given to a particular
logging.configyaml. Should be one word w/o special charactersFlavor is a very terse description, for a
genre, how this yaml differs from others. If completely generic, call itgeneric. If different handlers or formatters or filters are used, what is the yaml’s purpose?version_no¶ (Any | None) – Default 1. Version of this particular
genre. Not the version of the yaml spec. Don’t confuse the two.package_start_relative_folder¶ (pathlib.Path | str | None) – Default empty string which means search the entire package. Further narrows down search, so as to differentiate between folders which contain file with the same file name
logger_package_name¶ (str | None) – Set logger to the intended package name. Default None which leaves as-is
- Returns:
relative destination path to validated logging config YAML file and the yaml str
- Return type:
- Raises:
ImportError– package not installed in venvFileNotFoundError– yaml file not found within packagestrictyaml.exceptions.YAMLValidationError– yaml file validation failedAssertionError– Expecting one yaml file, many foundlogging_strict.LoggingStrictPackageNameRequired– Which package are the logging.config yaml in?logging_strict.LoggingStrictPackageStartFolderNameRequired– Within the provided package, the package base data folder name
- logging_strict.ui_yaml_curated(genre, flavor, version_no='1', package_start_relative_folder='', logger_package_name=None)¶
Curated within logging-strict So do not have to provide package and package base data folder name
- Parameters:
genre¶ (str) – UI framework or worker implementation characteristic. E.g. textual, rich, mp, or mq
version_no¶ (Any | None) – Default “1”. Applies to genre or genre & flavor
package_start_relative_folder¶ (str) –
Default empty string. Relative to package_data_folder_start. Relative path to further narrow down which folder contains the
logging.configyaml file.Needed when multiple folders contain
logging.configyaml file with same file namelogger_package_name¶ (str | None) – In logger dict, instead of the default package name, set a package name. Always desirable.
- Returns:
relative destination path to validated logging config YAML file and the yaml str
- Return type:
- logging_strict.worker_yaml_curated(genre='mp', flavor='asz', version_no='1', package_start_relative_folder='', logger_package_name=None)¶
For multiprocessing workers, retrieve the yaml in this order:
xdg user data dir folder
logging_strict package
If QA tester, modifies the exported logging.config yaml, those changes are not overwritten
Process 2nd step is calling:
setup_logging_yaml()- Parameters:
genre¶ (str | None) – Default “mp”. If UI: “textual” or “rich”. If worker: “mp”. Then can have a library of yaml files that can be used with a particular UI framework or worker type
Default “asz”. Unique identifier name given to a particular
logging.configyaml. Should be one word w/o special charactersFlavor is a very terse description, for a genre, how this yaml differs from others. If completely generic, call it
generic. If different handlers or formatters or filters are used, what is the yaml’s purpose?version_no¶ (Any | None) – Default 1. Version of this particular
genre. Not the version of the yaml spec. Don’t confuse the two.package_start_relative_folder¶ (pathlib.Path | str | None) – Default empty string which means search the entire package. Further narrows down search, so as to differentiate between folders which contain file with the same file name
logger_package_name¶ (str | None) – Set logger to the intended package name. Default None which leaves as-is
- Returns:
relative destination path to validated logging config YAML file and the yaml str
- Return type:
- Raises:
FileNotFoundError– yaml file not found within packagestrictyaml.exceptions.YAMLValidationError– yaml file validation failedAssertionError– Expecting one yaml file, many found