python


Why does Python's SysLogHandler require an address?


This code logs to syslog using the syslog module:
import syslog
syslog.syslog(syslog.LOG_ERR, 'a')
And here's the equivalent code using the logging module:
import logging
from logging.handlers import SysLogHandler
logger = logging.getLogger()
logger.addHandler(SysLogHandler(address='/dev/log'))
logger.setLevel(logging.ERROR)
logger.error('a')
If I leave out the address parameter in the second snippet, it doesn't do anything. Why does the logging version require me to specify an address, when the syslog module can figure it out on its own?
I'd rather not have to specify this path, since it's platform-dependent. Am I going to have to write my own version of SysLogHandler that delegates to the syslog module?
The syslog.syslog API allows you to send events to the system logger on the local machine only, whereas by specifying an address in Python logging you can log not only to the local machine but also a remote syslog server. So, the logging approach covers a wider set of circumstances than syslog.syslog does. Also note that on some platforms / in some environments, syslog.syslog was not always thread-safe (in the past), because the underlying system call API was not thread-safe in those environments. This may not be the case any longer, but it's best to check the documentation for syslog on your platform. For more background, see this Python issue.
Also, you can log to a syslog server from Windows machines too, using the logging API (The syslog module is not available on Windows).
From the documentation:
Note that if your server is not listening on UDP port 514, SysLogHandler may appear not to work.
Have you verified that your syslog is listening to the default port (514) used by SysLogHandler? If they aren't the same, then you will need to provide the specific port number or path to a log to use.
See: https://docs.python.org/2/library/logging.handlers.html#sysloghandler

Related Links

Google Admin SDK insert custom schema using python
Importing images for manifold Isomap
Having nosetests watch files from outside container and rerun tests inside container
Trying to ftp from my system to remote server
Attribute in a Class immediately runs at the wrong time?
Unable to handle “HTTP Badstatus line” exception
How to merge/join two resultset/table in django?
Maximise the Slope using CVXPY
Python-Instagram user_recent_media returning next of none
Django - AttributeError: 'module' object has no attribute 'admin'
Convert pandas (python) categorical x-axis to continuous values when plotting
How to make a specific type of python face tracker
OSError when trying to delete keys from redis
remove/reset matplotlib quiver arrows
Repeating elements in a list
Run python-rq worker process on application start

Categories

HOME
symfony
answer-set-programming
redis
itext
wildcard
json-ld
wms
safari
specflow
console
triggers
dropbear
window
cockroachdb
xlsx
viber
cratedb
bootstrap-popover
alfresco-share
ios10.3
logarithm
visual-c++-2017
kong
dss
cortex-m3
rhino
oscommerce
bing-maps-api
discord.net
concrete5-5.7
android-maps-v2
html-agility-pack
spring-bean
ajp
spell-checking
workflow-foundation-4.5
text-classification
photon-controller
jszip
castle-dynamicproxy
rxvt
rsqlite
inject
gradle-script-kotlin
packagemaker
update-site
visible
webkit2
gherkin
console-redirect
geodjango
mirrorlink
isml
google-hadoop
shift-jis
guzzle6
start-job
inputaccessoryview
belongs-to
lumx
zipalign
opensocial
xenocode
asp.net-mvc-scaffolding
leptonica
va-list
shiva3d
pep8
separation-of-concerns
jquery-selectbox
v4l
datamember
charts4j
dcpu-16
port-scanning
for-xml-path
hibernate3-maven-plugin
hardware-acceleration
task-management
delegatecommand
plinq
dirty-data
configurable
outlook-form
interface-design

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App