HelloZeroNet / ZeroNet

ZeroNet - Decentralized websites using Bitcoin crypto and BitTorrent network
https://zeronet.io
Other
18.3k stars 2.26k forks source link

[Android] Disable console logging if another logger is already hooked #2139

Open mkg20001 opened 5 years ago

mkg20001 commented 5 years ago

Step 1: Please describe your environment

Step 2: Describe the problem:

Steps to reproduce:

  1. Launch the zeronet android app (python3 branch) without the patch
  2. Watch it crash in the logs

Observed Results:

Expected Results:

Current workarround:

I'm applying this patch:

diff --git a/src/main.py b/src/main.py
index dfc32cc9..9f21ef2c 100644
--- a/src/main.py
+++ b/src/main.py
@@ -52,7 +52,7 @@ if config.action == "main":
                 print("Error starting browser: %s" % err)
         sys.exit()

-config.initLogging()
+config.initLogging(console_logging=False)

 # Debug dependent configuration

Instead this variable could be dynamically set, based on whether or not another logger is registered

purplesyringa commented 5 years ago

@mkg20001 Will a quick'n'dirty solution of adding a CLI option work, like what we have now with dist_type?

mkg20001 commented 5 years ago

This is kindof hard to do, since the service gets called in a non-standard way that does not allow any command line arguments.

As I said, I already have a quick'n'dirty solution (the patch I mentioned above)

Something more robust would be better, that's why I'm posting this.

mkg20001 commented 5 years ago

A possible fix would be to use an option in zeronet.conf for that. Something like disable_console_logger and disable_file_logger

purplesyringa commented 5 years ago

Will the following work:

import logging
config.initLogging(console_logging=len(logging.root.manager.loggerDict) == 0)

?

purplesyringa commented 5 years ago

@mkg20001 BTW, please set dist_type to kiwi or mobile or something. That'll make it easier to develop cross-platform sites (namely, administrating pages). You can set it either with CLI or with zeronet.conf (under [global] section)

mkg20001 commented 5 years ago

@imachug the fix detects other loggers and disables console logging in that case, right? Then it's perfect! :star:

For dist_type: I didn't know this existed :sweat_smile: Which one does the zeronet team prefer? kivy to indicate the kivy builds or android which specifially defined the platform. or something more specific such as android_9, or less such as mobile

purplesyringa commented 5 years ago

dist_type is source for raw Git repository (read: built from source) and bundle_x64 for ZeroNet bundle (not sure about underscore though, and whether it's x86 on 32-bit platforms). I've recommended people who make their own launchers to use bundle. I think using kivy makes most sense, and you'd use android as platform in serverInfo.

mkg20001 commented 5 years ago

I've set it to kivy. Or should I use bundle_kivy?

purplesyringa commented 5 years ago

Actually, I'd leave bundle* to the official zeronet.io bundle, so I'd use kivy instead.

HelloZeroNet commented 5 years ago

I have added new a --console_log_level off config option to disable the console logging: https://github.com/HelloZeroNet/ZeroNet/commit/7b9b48e62de8cd3de8c9368b16ad81185b5233e9

Right now the dist_type is used in the updater script to decide what runtime should be downloaded/updated beside the platform-independent py3 source code. I recommend to use kivy_android or bundle_kivy_android as it could be possible that kivy will be used for other platforms as well.

purplesyringa commented 5 years ago

Ok, using kivy_android makes sense now, I think. Also thanks for the commit, I believe this issue can be closed now.

Offtopic: could you check your ZeroMail please?

mkg20001 commented 5 years ago

I have added new a --console_log_level off config option to disable the console logging:

This is kindof hard to do, since the service gets called in a non-standard way that does not allow any command line arguments.

@HelloZeroNet We could have used the solution from https://github.com/HelloZeroNet/ZeroNet/issues/2139#issuecomment-520353194, since this looks like a solid workaround The proposed solution is kindof useless, unless I can set it via zeronet.conf

mkg20001 commented 5 years ago

Offtopic: could you check your ZeroMail please?

Uhm, I wasn't on ZeroNet for months now

Unsure if my .bit domains are even still registered :sweat_smile:

purplesyringa commented 5 years ago

@mkg20001 Uh, that off-topic was for nofish actually...