1
0
mirror of https://github.com/EDCD/EDMarketConnector.git synced 2025-04-24 04:30:54 +03:00

1776 Commits

Author SHA1 Message Date
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
307910739a Remove now un-necessary imports for logging/traceback 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
Athanasius
c196a38e09 Add logging TODOs. logger creation & frame detection
* Nothing should "from EDMarketConnector import logger" any more, so
 we can move this back inside __main__ section
* We shouldn't rely on a magic number of frames to skip.  Detect the
 proper frame automatically.
2020-07-27 06:57:52 +01:00
Athanasius
a82824c0e9 Contributing.md: Update logging docs for auto qualname and proper import 2020-07-27 06:57:52 +01:00
Athanasius
2e58d106bd logging.getLogger(appname) instead of import from EDMarketConnector
Using:

from EDMarketConnector import logger

causes issues if EDMarketConnector is already importing 'this' file.

So just get a logger using logger.getLogger(appname) instead.
`from config import appname` if needs be.
2020-07-27 06:57:52 +01:00
Athanasius
bae2f25e19 companion.py: Convert to proper logging 2020-07-27 06:57:52 +01:00
Athanasius
2176187be7 Fix typos in class/qualname finders 2020-07-27 06:57:52 +01:00
Athanasius
8e1f3b8a90 plugins/inara: Fix typo on except: 2020-07-27 06:57:52 +01:00
Athanasius
7d060aa325 plugins/inara: Convert to proper logging 2020-07-27 06:57:52 +01:00
Athanasius
4d7f81cec1 Add emergency print()s if we can't find class/qualname 2020-07-27 06:57:52 +01:00
Athanasius
89cadbc0eb Add paranoia checks to class and qualname finders 2020-07-27 06:57:52 +01:00
Athanasius
7951463fba plugins/edsm: Converted to proper logging 2020-07-27 06:57:52 +01:00
Athanasius
6aa409388e plugins/eddn: Converted to proper logging 2020-07-27 06:57:52 +01:00
Athanasius
818bd89fd7 Remove un-necessary {__class__} from logging messages 2020-07-27 06:57:52 +01:00
Athanasius
5af87a5b98 Clean up EDMarketConnector.py after that qualname testing 2020-07-27 06:57:52 +01:00
Athanasius
6b9d4a11cb Use a logging.Filter to implement %(qualname)s in formatting.
This gets the function that called the logging, and if it's in a class
it looks up the function via getattr(<class>, <func name>) and then
uses __qualname__ to quickly get the fully qualified name.
2020-07-27 06:57:52 +01:00
Athanasius
debc7f97d3 Use a logging.Filter to implement %(class)s in formatting. 2020-07-27 06:57:52 +01:00
Athanasius
2e12513c6c Changes plug.py to proper logging.
This relies on the logger.Formatter setup to fill in function name
rather than calling out exactly why we're logging.  It should be
obvious, i.e. if you're in plug.py:notify_journal_entry then the named
plugin threw an un-caught exception trying to call its method for this.
2020-07-27 06:57:52 +01:00
Athanasius
23b167fe66 Change startup version back to a print()
This is so early it doesn't need to be a spammy log message.
2020-07-27 06:57:27 +01:00
Athanasius
fe0ff2498e Moves logger definition so it's import'able 2020-07-27 06:57:23 +01:00
Athanasius
fa1443b49c Contributing.md: Document use of logging.
Also fixes some camelCase to be proper snake_case in an example.
2020-07-27 06:57:23 +01:00
Athanasius
c971106c0e Convert print()s to logging & refactor help_about -> HelpAbout 2020-07-27 06:57:23 +01:00
Athanasius
cd4216d19c logger setup and initialisation
* Initial printing of version is now a logger.info(...)
2020-07-26 23:16:52 +01:00
Athanasius
e1752506c5 Move "only run once" code into def enforce_single_instance() 2020-07-26 23:16:52 +01:00
A_D
5aaf88b281 fix quoting style 2020-07-26 23:08:47 +01:00
A_D
87b7f639bb cleanup coriolis.py 2020-07-26 23:08:47 +01:00
A_D
f08d60d9b1 revert using json.dump
windows encodings dont like the weird characters
2020-07-26 23:08:47 +01:00
A_D
0e0c802b04 Fixed missed whitespace after scope changes 2020-07-26 23:08:47 +01:00
A_D
64b9cb39a9 Replaced file.write(json.dumps()) with json.dump
There's no reason to use json.dumps and directly encode it when we can
let the json lib do the heavy lifting
2020-07-26 23:08:47 +01:00
A_D
566f52e61f removed uneeded parens 2020-07-26 23:08:47 +01:00
A_D
14295ce9e8 Fixed scope whitespace and long lines 2020-07-26 23:08:47 +01:00
A_D
8b0f3e74cf Replaced format directives with fstrings 2020-07-26 23:08:47 +01:00
A_D
c6d8b4eab8 Renamed variable for clarity 2020-07-26 23:08:47 +01:00
A_D
0e000de90a Replaced type annotation with Optional
The return is Optional so the annotation on the other side must be as
well, lest we have large red squiggles
2020-07-26 23:08:47 +01:00
A_D
3dfca91e1d Fixed invalid deep_get call 2020-07-26 23:08:47 +01:00
A_D
b6482878f0 Fix deep_get not returning the correct on success
I forgot to actually return the given data if we manage to index to the
requested depth
2020-07-26 23:08:47 +01:00
A_D
2403ed1d2f Replaced missed .get chains with deep_get 2020-07-26 23:08:47 +01:00
A_D
4ee8869426 Revert part of e510b783
Apparently config.get does _not_ take a default param. It really should.
2020-07-26 23:08:47 +01:00
A_D
664605a315 Cleaned up ifs where possible
Removed redundant or unneeded parens, correctly added line breaks where
needed
2020-07-26 23:08:47 +01:00
A_D
1ed9225c44 Added main guard
Modules should _always_ check that they are main before doing any "real"
work
2020-07-26 23:08:47 +01:00
A_D
637f58bb06 Replaced modulo-formatting with .format 2020-07-26 23:08:47 +01:00
A_D
0dfad42de3 Replaced .get chains with a new method
`deep_get` will go down a list of keys on a dict to find either the
requested key or the default if somewhere along the line the given dict
doesn't have a given key
2020-07-26 23:08:47 +01:00
A_D
8117e18963 Don't recompile regexps where possible
While the python re lib _does_ cache compiled regexps, it only does this
to a point, it's better to compile once and hold a reference
2020-07-26 23:08:47 +01:00
A_D
37c01c028c Replaced list comprehension with generator
Creating a list here doesnt make sense when its almost instantly
recreated.
2020-07-26 23:08:47 +01:00
A_D
31c049deda Replace sys.stderr.write call with print
`print()` supports files other than stdout, and will automatically add
newlines for us, among other things
2020-07-26 23:08:47 +01:00