languitar / broadcast-logging

A Python logging system handler which broadcasts log messages and a matching receiver executable.
GNU Lesser General Public License v3.0
3 stars 2 forks source link

Can't use on windows #1

Open Dodgexander opened 3 years ago

Dodgexander commented 3 years ago

I'm trying to setup remote logging for autosuspend and have followed the documentation and edited the autosuspend-logging.conf with the following:

[loggers]
keys=root,autosuspend,checks

[handlers]
keys=broadcastHandler
#keys=consoleHandler

[formatters]
keys=simpleFormatter

[logger_root]
level=INFO
handlers=broadcastHandler
#handlers=consoleHandler

[logger_autosuspend]
qualname=autosuspend
propagate=0
level=INFO
handlers=consoleHandler

[logger_checks]
qualname=autosuspend.checks
propagate=0
level=INFO
handlers=consoleHandler

[handler_consoleHandler]
class=StreamHandler
level=DEBUG
formatter=simpleFormatter
args=(sys.stdout,)

[formatter_simpleFormatter]
format=%(asctime)s - %(name)s - %(levelname)s - %(message)s
datefmt=

[handler_broadcastHandler]
class=broadcastlogging.BroadcastHandler
level=DEBUG
args=('192.168.0.255',55555)`

On a remote windows PC I have installed python 3.7 from the windows store, then installed this package using 'pip install broadcast-logging'

Using the example from the docs on the windows machine I enter:

python -m broadcastlogging -c -b '192.168.0.255' 55555

But I receive this error:

C:\Program Files (x86)\Windows Resource Kits\Tools>python -m broadcastlogging -c -b '192.168.0.255' 55555
Traceback (most recent call last):
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.7_3.7.2544.0_x64__qbz5n2kfra8p0\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.7_3.7.2544.0_x64__qbz5n2kfra8p0\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\dodge\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\broadcastlogging.py", line 152, in <module>
    receiver()
  File "C:\Users\dodge\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\broadcastlogging.py", line 105, in receiver
    sock.bind((args.bind, args.port))
socket.gaierror: [Errno 11001] getaddrinfo failed

I have tried changing the IP address to one on my own network, but its the same result. Something about the windows installation of this package doesn't seem to work for some reason. I've also searched online for a solution, and set my http and https proxy as my IP address in windows.

Any suggestions what could be wrong?

languitar commented 3 years ago

I've never tested this on Windows. But maybe the obvious question first: is 192.168.0.255 actually your broadcast address? What is your computer's IP address?

Dodgexander commented 3 years ago

The IP of my server is 192.168.50.149 but I keyed that in place of the example and it still gives the same error. I believe its something at the receivers end, not able to find or parse the IP address for some reason.

languitar commented 3 years ago

Just guessing I would say the broadcast address should be 192.168.50.255 then. That error message says that your system can't bind to that address. Or are the single quotes passed to the command on Windows?

Do you have a linux box to test the same command?

Dodgexander commented 3 years ago

Yep I tried that as my broadcast address as I figured it would be that from your example in the manual. I also tried without single quotes.

C:\Program Files (x86)\Minimal ADB and Fastboot>python -m broadcastlogging -c -b '192.168.50.255' 55555
Traceback (most recent call last):
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.7_3.7.2544.0_x64__qbz5n2kfra8p0\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.7_3.7.2544.0_x64__qbz5n2kfra8p0\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\dodge\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\broadcastlogging.py", line 152, in <module>
    receiver()
  File "C:\Users\dodge\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\broadcastlogging.py", line 105, in receiver
    sock.bind((args.bind, args.port))
socket.gaierror: [Errno 11001] getaddrinfo failed
C:\Program Files (x86)\Minimal ADB and Fastboot>python -m broadcastlogging -c -b 192.168.50.255 55555
Traceback (most recent call last):
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.7_3.7.2544.0_x64__qbz5n2kfra8p0\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.7_3.7.2544.0_x64__qbz5n2kfra8p0\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\dodge\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\broadcastlogging.py", line 152, in <module>
    receiver()
  File "C:\Users\dodge\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\broadcastlogging.py", line 105, in receiver
    sock.bind((args.bind, args.port))
OSError: [WinError 10049] The requested address is not valid in its context

I don't have another linux PC but I tried via my Android phone installing Python in the app: Termux. The result is different, I get [Errno 7] No address associated with hostname Here's my autosuspend-logging.conf

[loggers]
keys=root,autosuspend,checks

[handlers]
keys=broadcastHandler
#keys=consoleHandler

[formatters]
keys=simpleFormatter

[logger_root]
level=INFO
handlers=broadcastHandler
#handlers=consoleHandler

[logger_autosuspend]
qualname=autosuspend
propagate=0
level=INFO
handlers=consoleHandler

[logger_checks]
qualname=autosuspend.checks
propagate=0
level=INFO
handlers=consoleHandler

[handler_consoleHandler]
class=StreamHandler
level=DEBUG
formatter=simpleFormatter
args=(sys.stdout,)

[handler_broadcastHandler]
class=broadcastlogging.BroadcastHandler
level=DEBUG
args=('192.168.50.255',55555)

[formatter_simpleFormatter]
format=%(asctime)s - %(name)s - %(levelname)s - %(message)s
datefmt=

My autosuspend status is flagging something wrong, but unrelated to logging?

tim@basement:~$ systemctl status autosuspend.service
● autosuspend.service - A daemon to suspend your server in case of inactivity
     Loaded: loaded (/etc/systemd/system/autosuspend.service; enabled; vendor preset: enabled)
     Active: active (running) since Sat 2021-01-16 20:49:45 EST; 3s ago
       Docs: https://autosuspend.readthedocs.io/en/latest/systemd_integration.html
   Main PID: 443950 (autosuspend)
      Tasks: 1 (limit: 18738)
     Memory: 15.1M
     CGroup: /system.slice/autosuspend.service
             └─443950 /usr/bin/python3 /usr/local/bin/autosuspend -l /etc/autosuspend-logging.conf daemon

Jan 16 20:49:45 basement systemd[1]: Started A daemon to suspend your server in case of inactivity.
Jan 16 20:49:45 basement autosuspend[443950]: Unable to configure logging from file <_io.TextIOWrapper name='/etc/autosuspend-logging.conf' mode='r' encoding='UTF-8'>. Falling back to warning level.
Jan 16 20:49:45 basement autosuspend[443950]: Traceback (most recent call last):
Jan 16 20:49:45 basement autosuspend[443950]:   File "/usr/local/lib/python3.8/dist-packages/autosuspend-.-py3.8.egg/autosuspend/__init__.py", line 608, in configure_logging
Jan 16 20:49:45 basement autosuspend[443950]:     logging.config.fileConfig(config_file)
Jan 16 20:49:45 basement autosuspend[443950]:   File "/usr/lib/python3.8/logging/config.py", line 80, in fileConfig
Jan 16 20:49:45 basement autosuspend[443950]:     _install_loggers(cp, handlers, disable_existing_loggers)
Jan 16 20:49:45 basement autosuspend[443950]:   File "/usr/lib/python3.8/logging/config.py", line 252, in _install_loggers
Jan 16 20:49:45 basement autosuspend[443950]:     logger.addHandler(handlers[hand])
Jan 16 20:49:45 basement autosuspend[443950]: KeyError: 'consoleHandler'

Aim is to log remotely if I can, since I'm seeing autosuspend suspending my system even when criteria should be met, the problem is, I can never see exactly when it happens if I can only trace past logs :)

EDIT* can't seem to stop the key errors in the autosuspend status, not sure if its related?

languitar commented 3 years ago

EDIT* can't seem to stop the key errors in the autosuspend status, not sure if its related?

Your section logger_autosuspend still references consoleHandler but that handler isn't part of the handlers section anymore.

I'll have to check for the Windows errors. Maybe things work differently there.

Dodgexander commented 3 years ago

thanks. I edited out where I saw consoleHandler and changed it to broadcast handler but I still get errors.

● autosuspend.service - A daemon to suspend your server in case of inactivity
     Loaded: loaded (/etc/systemd/system/autosuspend.service; enabled; vendor preset: enabled)
     Active: active (running) since Sun 2021-01-24 13:31:07 EST; 7s ago
       Docs: https://autosuspend.readthedocs.io/en/latest/systemd_integration.html
   Main PID: 2011963 (autosuspend)
      Tasks: 1 (limit: 18738)
     Memory: 16.0M
     CGroup: /system.slice/autosuspend.service
             └─2011963 /usr/bin/python3 /usr/local/bin/autosuspend -l /etc/autosuspend-logging.conf daemon

Jan 24 13:31:07 basement autosuspend[2011963]: Traceback (most recent call last):
Jan 24 13:31:07 basement autosuspend[2011963]:   File "/usr/local/lib/python3.8/dist-packages/autosuspend-.-py3.8.egg/autosuspend/__init__.py", line 608, in configure_logging
Jan 24 13:31:07 basement autosuspend[2011963]:     logging.config.fileConfig(config_file)
Jan 24 13:31:07 basement autosuspend[2011963]:   File "/usr/lib/python3.8/logging/config.py", line 80, in fileConfig
Jan 24 13:31:07 basement autosuspend[2011963]:     _install_loggers(cp, handlers, disable_existing_loggers)
Jan 24 13:31:07 basement autosuspend[2011963]:   File "/usr/lib/python3.8/logging/config.py", line 199, in _install_loggers
Jan 24 13:31:07 basement autosuspend[2011963]:     hlist = section["handlers"]
Jan 24 13:31:07 basement autosuspend[2011963]:   File "/usr/lib/python3.8/configparser.py", line 1254, in __getitem__
Jan 24 13:31:07 basement autosuspend[2011963]:     raise KeyError(key)
Jan 24 13:31:07 basement autosuspend[2011963]: KeyError: 'handlers'
GNU nano 4.8                                                                                                                                    /etc/autosuspend-logging.conf
[loggers]
keys=root,autosuspend,checks

[handlers]
keys=broadcastHandler
#keys=consoleHandler

[formatters]
keys=simpleFormatter

[logger_root]
level=INFO
handler=broadcastHandler
#handlers=consoleHandler

[logger_autosuspend]
qualname=autosuspend
propagate=0
level=INFO
handler=broadcastHandler
#handlers=consoleHandler

[logger_checks]
qualname=autosuspend.checks
propagate=0
level=INFO
handler=broadcastHandler

#[handler_consoleHandler]
#class=StreamHandler
#level=DEBUG
#formatter=simpleFormatter
#args=(sys.stdout,)

[handler_broadcastHandler]
class=broadcastlogging.BroadcastHandler
level=DEBUG
args=('192.168.50.255',55555)

[formatter_simpleFormatter]
format=%(asctime)s - %(name)s - %(levelname)s - %(message)s
datefmt=

I've commented out sections I want to keep in the future for local logging.

languitar commented 3 years ago

Take a look at your changes:

handler=broadcastHandler
#handlers=consoleHandler

handler != handlerS

languitar commented 3 years ago

Btw, you can easily have local and broadcast logging in parallel

Dodgexander commented 3 years ago

Great! It was just a typo after all, got the broadcast-logging up and running on my phone now using Termux (installing python within the app) and it works great.

The problem seems to stem from a change in how the program interprets the IP address command in windows. sock.bind((args.bind, args.port)) socket.gaierror: [Errno 11001] getaddrinfo failed

Just seems to me like the passing of IP in windows just doesn't work properly for some reason. Either that or there's a configuration error on my setup not allowing python to resolve the IP.