1
0
Commit Graph

29 Commits

Author SHA1 Message Date
SomberNight
7542378c70 set stricter UNIX permissions for log files
Looks like stdlib was creating them with 0o664 :/
2024-10-07 18:50:26 +00:00
SomberNight
d54184dbc1 fix some DeprecationWarnings in python3.12
...\electrum\electrum\logging.py:137: DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
...\electrum\electrum\x509.py:310: DeprecationWarning: datetime.datetime.utcfromtimestamp() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.fromtimestamp(timestamp, datetime.UTC).
2023-12-24 08:57:57 +00:00
SomberNight
5e8b14f742 logging: add config var "LOGS_NUM_FILES_KEEP" instead of hardcoded 10 2023-09-06 16:55:04 +00:00
SomberNight
b45c84f24f remove the kivy gui
We now use the qml gui on Android, and haven't been maintaining
the kivy GUI for a while.
2023-08-30 16:47:37 +00:00
SomberNight
24980feab7 config: introduce ConfigVars
A new config API is introduced, and ~all of the codebase is adapted to it.
The old API is kept but mainly only for dynamic usage where its extra flexibility is needed.

Using examples, the old config API looked this:
```
>>> config.get("request_expiry", 86400)
604800
>>> config.set_key("request_expiry", 86400)
>>>
```

The new config API instead:
```
>>> config.WALLET_PAYREQ_EXPIRY_SECONDS
604800
>>> config.WALLET_PAYREQ_EXPIRY_SECONDS = 86400
>>>
```

The old API operated on arbitrary string keys, the new one uses
a static ~enum-like list of variables.

With the new API:
- there is a single centralised list of config variables, as opposed to
  these being scattered all over
- no more duplication of default values (in the getters)
- there is now some (minimal for now) type-validation/conversion for
  the config values

closes https://github.com/spesmilo/electrum/pull/5640
closes https://github.com/spesmilo/electrum/pull/5649

Note: there is yet a third API added here, for certain niche/abstract use-cases,
where we need a reference to the config variable itself.
It should only be used when needed:
```
>>> var = config.cv.WALLET_PAYREQ_EXPIRY_SECONDS
>>> var
<ConfigVarWithConfig key='request_expiry'>
>>> var.get()
604800
>>> var.set(3600)
>>> var.get_default_value()
86400
>>> var.is_set()
True
>>> var.is_modifiable()
True
```
2023-05-25 17:39:48 +00:00
SomberNight
748f15e94c simplify prev 2022-11-06 06:22:50 +00:00
SomberNight
111043f8b4 logging: add a relative timestamp to stderr console logs
In the past we decided not to put a timestamp into the stderr logs
to have shorter log lines (to save column width in a terminal).
However over time I at least have found that it would be valuable
to have timestamps also in the stderr - e.g. when users provide logs.
Often I am only interested in the time taken between logged events,
so as a compromise to still save some length, I propose adding relative
timestamps (relative to process startup time).

Compare these log lines from the file logger:

```
20220816T120601.882003Z |     INFO | gui.qt.ElectrumGui | starting Qt main loop
20220816T120601.905619Z |     INFO | gui.qt.history_list.HistoryModel | refreshing... reason: update_tabs
20220816T120601.911908Z |    DEBUG | util.profiler | Abstract_Wallet.get_full_history 0.0059 sec
20220816T120602.095670Z |     INFO | interface.[testnet.hsmiths.com:53012] | connection established. version: ['ElectrumX 1.16.0', '1.4']
```
With these from the existing stderr logger:
```
I/w | wallet.Standard_Wallet.[test_segwit_3] | set_up_to_date: True
I/i | interface.[testnet.aranguren.org:51002] | set blockchain with height 2343721
D | util.profiler | ElectrumWindow.load_wallet 0.0778 sec
I | gui.qt.ElectrumGui | starting Qt main loop
```
With these re what I propose for the stderr logger:
```
  3.20 | D | util.profiler | Abstract_Wallet.get_full_history 0.0029 sec
  5.70 | I | i/interface.[testnet1.bauerj.eu:50002] | disconnecting due to: ConnectError(ConnectionRefusedError(22, 'The remote computer refused the network connection', None, 1225, None))
 38.63 | I | w/wallet.Standard_Wallet.[9dk] | starting taskgroup.
 38.84 | D | util.profiler | WalletDB._write 0.0059 sec
 62.96 | I | i/interface.[blockstream.info:993] | set blockchain with height 2343722
150.65 | I | exchange_rate.CoinGecko | getting fx quotes for EUR
```
2022-11-06 06:20:41 +00:00
SomberNight
eb2ff94104 android: when running debug apk, disallow changing "enable_debug_logs"
follow-up 34b594ea40
2022-11-04 02:40:04 +00:00
SomberNight
34b594ea40 android: add setting to enable debug logs
If enabled, we log to stderr, which can get inspected via logcat.
Not user-friendly at all - but previously there was no way to get logs from a release build.

closes https://github.com/spesmilo/electrum/issues/7409
2022-10-07 20:28:52 +00:00
SomberNight
e72f575eea android build: factor out package name ("org.electrum.electrum")
to make it easier to change, to make it easy to have a co-existing mainnet and testnet install
(or two mainnet installs, etc)
2022-07-09 04:47:32 +02:00
Sander van Grieken
64de9807ac remove kivy platform check 2022-07-07 18:28:00 +02:00
SomberNight
ffe36e2f56 make "-v" (logging to stderr) work with commands
When running a command, file logging is disabled as every
command-invocation would create a new logfile. However if the user
explicitly sets "-v" on the commandline, there's no reason why that
shouldn't work.
2022-06-12 00:54:35 +02:00
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