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

Psycopg2 Postgre Connection retries
Error for pyspark converting dataframe to rdd
Signal generator specifitc noise modulation
Difference between os.execl() and os.execv() in python
Replace words into special string except nouns and adjectives in Python
Getting private key from ServiceResource create_key_pair
Removing strings from a list that contain dates, without effecting stand alone dates in the list
xliff and placeable substitution
Checking that array doesn't contain negative numbers, and running function again if it does
Matplotlib and non-ascii characters
How does HttpResponse(status=<code>) work in django?
Write a CSV from Urlib and manage encoding properly
python - list index out of range, working with CSV?
Pandas DataFrame get substrings from column
Python GET is not working in browser
Django, Pinax, couldn't extract file

Categories

HOME
xbox-live
facebook-graph-api
backup
translation
formal-verification
playframework
webdav
user
lotus-notes
window
ndis
game-maker-studio-1.4
uiscrollview
tee
mongodb-query
react-leaflet
phpbb
grub2
jpeg2000
attask
tweets
os161
avplayeritem
fabric
guile
superagent
hibernate-cache
entity-system
oracle-xml-db
geopy
nsurlconnection
rhino
hashcat
wfp
rhel.net
parent
wcf-security
react-native-router-flux
paho
amd
encapsulation
3scale
ajp
webdatagrid
goquery
ruby-on-rails-2
photon-controller
httplib2
in-memory-database
pycurl
addin-express
iron.io
polar-coordinates
typhoon
hspec
radians
spatial-query
achievements
code-readability
sourcegear-vault
lmfit
oai
vine
lines-of-code
pgm
gulp-livereload
scrollspy
guzzle6
ember-cli-addons
hiera
obfuscar
utf-32
errorprovider
dalekjs
genetic-programming
method-overriding
adaptive-compression
colt
level
unison
dynamic-proxy
healthvault
wic
lame
graph-coloring
wpdb
dynamic-data
macruby
die
file-exists
viewdidload
throttling
datacontract
sendfile
pivotal-crm
recordset
camtasia
graniteds
windows-controls
cots

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