Sean Keane
Sean Keane

Reputation: 411

Python import syslog on windows

I have a python script that is normally run on a unix machine, I am trying to run it on windows. The one snag I have run into is the module syslog. Is there a way that anyone knows that I can get around this on a windows machine, is there an equivalent package for windows? Running python 2.7.

Upvotes: 10

Views: 9784

Answers (2)

vav
vav

Reputation: 4694

You can create syslog.py and put it somewhere in a python path. You also can customize it to actually write messages down or send them over network.

My version below. (It misses few functions and constants, so you may need to add some more):

import sys

LOG_EMERG, LOG_ALERT, LOG_CRIT, LOG_ERR, LOG_WARNING, \
LOG_NOTICE, LOG_INFO, LOG_DEBUG = range(8)

LOG_KERN, LOG_USER, LOG_MAIL, LOG_DAEMON, LOG_AUTH, \
LOG_SYSLOG, LOG_LPR, LOG_NEWS, LOG_UUCP = range(0,65,8)

LOG_CRON = 120
LOG_LOCAL0 = 128
LOG_LOCAL1 = 136
LOG_LOCAL2 = 144
LOG_LOCAL3 = 152
LOG_LOCAL4 = 160
LOG_LOCAL5 = 168
LOG_LOCAL6 = 176
LOG_LOCAL7 = 184

LOG_PID = 1
LOG_CONS = 2
LOG_NDELAY = 8
LOG_NOWAIT = 16

def syslog(message):
pass

def syslog(priority, message):
pass

def openlog(ident=sys.argv[0], logoptions=0, facility=LOG_USER):
pass

def closelog():
pass

def setlogmask(maskpri):
pass

Upvotes: 12

Phillammon
Phillammon

Reputation: 204

The "logging" module should be ideal for what you're looking for, though it may require some rewriting of the code. It also has the advantage that logging is platform independent, so it works on both Windows and *nix, which is always handy.

Upvotes: 1

Related Questions