'Python send logs via ssh tunnel not working
I have a simple test application in python that I would like to run through ssh tunnel: Here is the application code :
import logging
import logging.handlers
my_logger = logging.getLogger('MyLogger')
my_logger.setLevel(logging.DEBUG)
handler = logging.handlers.SysLogHandler(address = ('localhost',6000), facility=19)
my_logger.addHandler(handler)
my_logger.debug('this is debug')
my_logger.critical('this is critical')
On the other hand, I run this on my local machine:
ssh -L 6000:0.0.0.0:8000 user@remotehost
my goal is to send log via secure channel.
Note:
Application is running perfectly without ssh tunnel from local computer to the server.
I am able to test that tunnel is working fine because when I use curl localhost:6000
I get a result on the other side, this mean ssh tunnel is working as expected.
Can someone see what I am doing wrong ?
BR,
Edited :
after few checks, I saw that http was missing:
import logging
import logging.handlers
import requests
import socket
logging.socket = socket
my_logger = logging.getLogger('MyLogger')
my_logger.setLevel(logging.DEBUG)
#handler = logging.handlers.SysLogHandler(address = '/dev/log')
handler = logging.handlers.SysLogHandler(address = ('http://localhost', 6000))
my_logger.addHandler(handler)
my_logger.debug('this is debug')
my_logger.critical('this is critical')
now, I have this error messae:
Traceback (most recent call last):
File "/home/user/Documents/python-scripts/projects/psyslogc/./demo.py", line 15, in <module>
handler = logging.handlers.SysLogHandler(address = ('http://localhost', 6000))
File "/usr/lib/python3.10/logging/handlers.py", line 878, in __init__
ress = socket.getaddrinfo(host, port, 0, socktype)
File "/usr/lib/python3.10/socket.py", line 955, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -2] Name or service not known
Exception ignored in atexit callback: <function shutdown at 0x7f6a3b2aea70>
Traceback (most recent call last):
File "/usr/lib/python3.10/logging/__init__.py", line 2183, in shutdown
h.close()
File "/usr/lib/python3.10/logging/handlers.py", line 941, in close
self.socket.close()
AttributeError: 'SysLogHandler' object has no attribute 'socket'
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
