1
0
Commit Graph

17 Commits

Author SHA1 Message Date
SomberNight
9a38c4d2a1 logging: don't lose log messages during early startup
Previously, during early-startup (until configure_logging(config) is
called in run_electrum),
- the stderr log handler lost all log messages below warning level, and
- the file log handler lost all log messages regardless of log level

We now instead start buffering log messages in memory as soon as
electrum.logging is imported. The buffer is dumped into the
stderr and file log handlers when they are fully set up, and then
the buffer is discarded (and the temporary log handler is removed).

Note that messages are not logged until configure_logging() is called.
Previously WARNING/ERROR messages would get logged immediately to stderr,
but not anymore. This was changed so that the order of the log messages
can be kept intact. (if we log WARNINGs immediately, but need to delay
INFOs until the config is available, messages would either be out of order
or alternatively there would be duplicates)

Relatedly, we now follow the recommendation of the python docs re
logging for libraries [0]: we try to only configure logging if running via
run_electrum (the main script) and not when e.g. a 3rd party script
imports electrum.

[0]: https://docs.python.org/3/howto/logging.html#configuring-logging-for-a-library
2021-04-14 19:14:26 +02:00
SomberNight
6650e6bbae logging: (move-only) move module level code to near the end 2021-04-14 19:13:27 +02:00
SomberNight
7335a584e7 logging: handle "cannot delete old logfile" error
E.g. on Windows, files open in one process cannot be deleted by another process.
With file logging enabled, if an old logfile was open in a text editor,
Electrum could crash during startup.

```
E | __main__ |
Traceback (most recent call last):
  File "...\electrum\run_electrum", line 391, in main
    handle_cmd(
  File "...\electrum\run_electrum", line 403, in handle_cmd
    configure_logging(config)
  File "...\electrum\electrum\logging.py", line 278, in configure_logging
    _configure_file_logging(log_directory)
  File "...\electrum\electrum\logging.py", line 107, in _configure_file_logging
    _delete_old_logs(log_directory)
  File "...\electrum\electrum\logging.py", line 98, in _delete_old_logs
    os.remove(str(f))
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: '...\\AppData\\Roaming\\Electrum\\testnet\\logs\\electrum_log_20210414T023751Z_25008.log'
```
2021-04-14 05:10:54 +02:00
SomberNight
d4de25a8cd crash reports: fix get_git_version for kivy 2021-03-10 16:23:49 +01:00
SomberNight
ef744f164b logging: make sure file logging uses utf8 encoding
--- Logging error ---
Traceback (most recent call last):
  File "...\Python38\lib\logging\__init__.py", line 1084, in emit
    stream.write(msg + self.terminator)
  File "...\Python38\lib\encodings\cp1252.py", line 19, in encode
    return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\u26a1' in position 80: character maps to <undefined>
Call stack:
  File ".../electrum/run_electrum", line 466, in <module>
    main()
  File ".../electrum/run_electrum", line 384, in main
    handle_cmd(
  File ".../electrum/run_electrum", line 402, in handle_cmd
    d.run_gui(config, plugins)
  File "...\electrum\electrum\daemon.py", line 572, in run_gui
    self.gui_object.main()
  File "...\electrum\electrum\gui\qt\__init__.py", line 391, in main
    self.app.exec_()
  File "...\electrum\electrum\gui\qt\channels_list.py", line 308, in new_channel_with_warning
    self.new_channel_dialog()
  File "...\electrum\electrum\gui\qt\channels_list.py", line 390, in new_channel_dialog
    if not d.exec_():
  File "...\electrum\electrum\gui\qt\channels_list.py", line 358, in on_suggest
    nodeid = bh2u(lnworker.lnrater.suggest_peer() or b'')
  File "...\electrum\electrum\lnrater.py", line 257, in suggest_peer
    return self.suggest_node_channel_open()[0]
  File "...\electrum\electrum\lnrater.py", line 248, in suggest_node_channel_open
    self.logger.info(
Message: 'node rating for Bottlepay:\nNodeStats(number_channels=20, total_capacity_msat=167455866000, median_capacity_msat=8460000000.0, mean_capacity_msat=8372793300.0, node_age_block_height=71003, mean_channel_age_block_height=48581.39999999991, blocks_since_last_channel=507, mean_fee_rate=1e-06) (score 0.5034595626052799)'
Arguments: ()
2020-11-16 14:50:22 +01:00
SomberNight
625f985f22 android: enable full logging if DEBUG build 2020-06-19 01:52:21 +02:00
Christian Clauss
e34afd62ce Travis CI: Use flake8 to find Python syntax errors and undefined names (#5467) 2019-08-11 22:35:23 +00:00
SomberNight
650225e238 crash reporter UX
see #5483
2019-07-04 19:13:12 +02:00
SomberNight
f6a7e6ec7d logging: don't log to file by default
Leaking addresses/pubkeys/txids is a privacy leak...
but with lightning, logging should be enabled by default, as otherwise
issues would be sometimes impossible to debug...
Well, disable it for now.
2019-05-08 16:52:04 +02:00
SomberNight
104b8804f7 logging: '-V' cli option can blacklist/whitelist classes with short names
for example, '-V ni' will whitelist the 'Network' and 'Interface' classes
'-V ^ni' will blacklist those instead
2019-05-07 21:07:18 +02:00
SomberNight
7a99fdc275 kivy: fix crash in logging.py; platform.platform() not available 2019-05-06 19:10:29 +02:00
SomberNight
387834164c logging: port ugly accidental side-effect into readable explicit feature
LogFormatterForConsole.format() was mutating its 'record' argument,
which was affecting all handlers/formatters
2019-05-02 16:05:26 +02:00
SomberNight
a7b13f4876 logging: make console log lines shorter 2019-05-02 15:19:11 +02:00
SomberNight
f22a23aaf2 logging: fix for kivy 2019-05-02 15:19:10 +02:00
SomberNight
6940c424d1 logging: cli options to filter for modules using -v
old style "-v" still works

filtering examples:
-v=debug,network=error,interface=error      // effectively blacklists network and interface
-v=warning,network=debug,interface=debug    // effectively whitelists network and interface
2019-05-02 15:19:10 +02:00
SomberNight
3385a94753 logging: basics 2019-05-02 15:19:03 +02:00
cluelessperson
4d64e132d7 standardized logging base with ISO8601, UTC, rotating file logs, and more! 2019-05-02 15:07:15 +02:00