1
0
mirror of https://github.com/EDCD/EDMarketConnector.git synced 2025-04-14 08:17:13 +03:00

77 Commits

Author SHA1 Message Date
Athanasius
5c9c9e2056 Logging: Default loglevel now INFO
We have EDMC CL arg and GUI selection of loglevel now, stored in
settings, so default can be INFO.
2020-09-07 13:14:20 +01:00
Athanasius
3a31139cbd Correct frame_info type 2020-07-31 14:46:38 +01:00
Athanasius
efe63ceac9 Refactor caller_attributes() code into separate methods
* find_caller_frame() to do the frame walk.
* munge_module_name() to fix up for plugins.

NB: caller_attributes() now has a noqa on CCR001 as I don't think it
can sensibly be made any less complex.  Pulling out the 'if frame:'
section just results in *that* new method then being labelled as too
complex.:244
2020-07-31 14:46:38 +01:00
Athanasius
282e3ddbc5 Fix up and expand on docstrings. 2020-07-31 14:46:38 +01:00
Athanasius
657253b3e3 Set internal and found plugin module_name separately.
* Settled on `plugins.internal` and `<plugins>.found` as the format.
* A PyCharm recommendation was to use 'cls' instead of 'self' on class
 methods, so the class detection code needs to cater for that.
 Technically a developer could use any string for the "myself" member
 name, but we'll assume just these two.
* Found will always have at least one folder level within plugin_dir
* Internal should always have *no* folder within internal_plugin_dir,
 but cater for it just in case in future.
2020-07-31 14:46:38 +01:00
Athanasius
89f2726e48 Set internal and found plugin module_name separately.
Settled on `plugins.<internal` and `<plugins>.found` as the format.
2020-07-31 14:46:38 +01:00
Athanasius
ad021e0765 Remove %(class)s from logging format as un-necessary.
It was only there to test the code populating it.
2020-07-31 14:46:38 +01:00
Athanasius
beea4ef39b Remove %(name)s from logging format as un-necessary. 2020-07-31 14:46:38 +01:00
Athanasius
e3b3f1e5b5 Prepend some useful information to %(module)s if caller is a plugin
NB: This assumes only one level within the plugin folder, TODO to fix
    that.
2020-07-31 14:46:38 +01:00
Athanasius
e572395718 LoggerAdapter can't change anything but %(message)s 2020-07-31 14:46:38 +01:00
Athanasius
04c4f5e683 Using a LoggerAdapter to prepend a string.
1. This makes setting up logging everywhere slightly more involved.
2. If I then want to change, say, %(module)s value I'll end up needing
 to stack walk again.

So this might be better done in a filter.  But these commits for the
record, and to come back to if needs be.
2020-07-31 14:46:38 +01:00
Athanasius
898ff9fbb2 Logging: Make correct loggers for 'found' plugins
* Log messages propagate up Parent.Child chains, so we don't need a
 channel on the plugin logger.
* But it still needs the filter to define qualname and class for
 formatting.
2020-07-31 14:46:38 +01:00
Athanasius
1352931465 Remove EDMCLogging.py comment to trigger diff 2020-07-31 13:50:27 +01:00
Athanasius
e430246d5b Add comment to trigger change 2020-07-31 12:07:52 +01:00
Athanasius
45ef87bcb4 Correct frame typing, and import clean up.
Also explains why we're doing that _getframe import that way.
2020-07-29 15:02:47 +01:00
Athanasius
589bc0b5f1 Cover all cases with inspect
* <module> works.
* top-level function in <module> works, presumably also any other file.
* Call from within classes works.
* Extra, commented out, test cases in EDMarketConnector.py
2020-07-29 15:02:47 +01:00
Athanasius
1989b272eb Use inspect to get frame information for qualname
Also includes some minor tweaks to make PyCharm happier:

* @classmethod caller_class_and_qualname().
* No need to () when "returning a tuple".
2020-07-29 15:02:47 +01:00
Athanasius
7a8f29edcf Add comments about future unit tests to implement.
Some of these won't even have been manually tested yet, so might require
more updates to the frame-walking function.
2020-07-29 15:02:47 +01:00
Athanasius
a3b7dcbedc Logging: Handle 'bare function' caller for class/qualname 2020-07-29 15:02:47 +01:00
Athanasius
6429cae932 Use isinstance() for type checking 2020-07-27 10:37:36 +01:00
Athanasius
d7c2372417 Flake8 cleanup round #2 2020-07-27 10:14:16 +01:00
Athanasius
f9a23cc831 Clean up flake8 output for this branch 2020-07-27 09:37:10 +01:00
Athanasius
3653a1342f No need to subclass object. 2020-07-27 06:57:53 +01:00
Athanasius
66e2c354c7 Documentation update and getLogger() -> get_logger()
* Technically %(class)s can be e.g. A.B not just 'B' so say "name(s)".
* To not confuse EDMCLogging.getLogger() with logging.getLogger() it's
 been renamed to get_logger().
* Note how we signal errors with finding class and/or qualname.
* Call out EDMCLogging.py in Contributing.md.
2020-07-27 06:57:53 +01:00
Athanasius
2eba647f17 Simply walk up the stack finding the frame we want.
Also leave that 'A.B' test around as a hint for a unittest.  Obviously
that instantiation will need commenting out for a release.
2020-07-27 06:57:53 +01:00
Athanasius
5a779a3379 Cleanups and docstrings
* Added/fleshed out docstrings on file, classes and functions.
* No need to use a function for the stack frame getting.
* Check if LogRecord has class or qualname before setting, allowing
 upstream to implement them.
* Use setattr()/getattr() rather than __dict__ fiddling.
* Force an error string into class/qualname if we have issues finding
 them, rather than failing silently to ''.
2020-07-27 06:57:53 +01:00
Athanasius
596527bda2 Move logging setup to EDMCLogging.py with a class
* Also now providers single caller_class_and_qualname() method to get
 both strings, returned as a Tuple[str, str].  Either could be empty
 if something went wrong.
* Rather than a fragile 'skip' this now:
    1. Looks for the first up-stack frame with self of logging.Logger
    1. Then looks for the next up-stack frame with self NOT of
     logging.Logger.  This should be the call site we want.
2020-07-27 06:57:53 +01:00