Python syslog.LOG_ALERT Examples

The following are 9 code examples of syslog.LOG_ALERT(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module syslog , or try the search function .
Example #1
Source File: test_syslog.py    From Safejumper-for-Desktop with GNU General Public License v2.0 5 votes vote down vote up
def test_emitErrorPriority(self):
        """
        L{SyslogObserver.emit} uses C{LOG_ALERT} if the event represents an
        error.
        """
        self.observer.emit({
                'message': ('hello, world',), 'isError': True, 'system': '-',
                'failure': Failure(Exception("foo"))})
        self.assertEqual(
            self.events,
            [(stdsyslog.LOG_ALERT, '[-] hello, world')]) 
Example #2
Source File: logging.py    From pycopia with Apache License 2.0 5 votes vote down vote up
def alert(msg):
    syslog.syslog(syslog.LOG_ALERT, _encode(msg)) 
Example #3
Source File: logging.py    From pycopia with Apache License 2.0 5 votes vote down vote up
def loglevel_alert():
    loglevel(syslog.LOG_ALERT)


# common logging patterns 
Example #4
Source File: test_syslog.py    From learn_python3_spider with MIT License 5 votes vote down vote up
def test_emitErrorPriority(self):
        """
        L{SyslogObserver.emit} uses C{LOG_ALERT} if the event represents an
        error.
        """
        self.observer.emit({
                'message': ('hello, world',), 'isError': True, 'system': '-',
                'failure': Failure(Exception("foo"))})
        self.assertEqual(
            self.events,
            [(stdsyslog.LOG_ALERT, '[-] hello, world')]) 
Example #5
Source File: test_syslog.py    From python-for-android with Apache License 2.0 5 votes vote down vote up
def test_emitErrorPriority(self):
        """
        L{SyslogObserver.emit} uses C{LOG_ALERT} if the event represents an
        error.
        """
        self.observer.emit({
                'message': ('hello, world',), 'isError': True, 'system': '-',
                'failure': Failure(Exception("foo"))})
        self.assertEqual(
            self.events,
            [(stdsyslog.LOG_ALERT, '[-] hello, world')]) 
Example #6
Source File: SavingThrow.py    From SavingThrow with GNU General Public License v3.0 5 votes vote down vote up
def log(self, message, log_level=syslog.LOG_ALERT):
        """Log to the syslog, and if verbose, also to stdout."""
        syslog.syslog(log_level, message)
        if self.verbose:
            print message 
Example #7
Source File: SavingThrow.py    From SavingThrow with GNU General Public License v3.0 5 votes vote down vote up
def vlog(cls, message, log_level=syslog.LOG_ALERT):
        """Log to the syslog and to stdout."""
        syslog.syslog(log_level, message)
        print message 
Example #8
Source File: laikamilter.py    From laikaboss with Apache License 2.0 5 votes vote down vote up
def _logMail(self, individualReceiver):
       
        if self.rulesMatched == "None":  #Remove the "None" used to differentiate between no result and result with No rules matched to save space in log file.  
            self.rulesMatched = ""
        self.endTime = time.time()
        timeDiff = int((self.endTime - self.startTime)*100000) # Convert to Microsec
        timeDiffZMQ = int((self.endTimeZMQ - self.startTimeZMQ)*100000) # Convert to Microsec
        log = "%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s"%(self._logMail_sanitize(self.archiveFileName),
                                                                                                  self._logMail_sanitize(self.messageID),
                                                                                                  self._logMail_sanitize(self.milterConfig.milterInstance),
                                                                                                  self._logMail_sanitize(self.rulesMatched),
                                                                                                  self._logMail_sanitize(self.dispositions),
                                                                                                  self._logMail_sanitize(self.attachments),
                                                                                                  self._logMail_sanitize(self.sender),
                                                                                                  self._logMail_sanitize(self._getClientAddr()),
                                                                                                  self._logMail_sanitize(individualReceiver),
                                                                                                  self._logMail_sanitize(self._getIfAddr()),
                                                                                                  self._logMail_sanitize(self.messageDate),
                                                                                                  #self._logMail_sanitize(timeDiff),
                                                                                                  self._logMail_sanitize(self.milterConfig._unconvertDispositionMode(self.rtnToMTA)),
                                                                                                  self._logMail_sanitize(self.qid),
                                                                                                  self._logMail_sanitize(""),               #TODO: scanner IP?
                                                                                                  self._logMail_sanitize(timeDiffZMQ),
                                                                                                  self._logMail_sanitize(self.subject))
        
        self.logger.writeLog(syslog.LOG_ALERT, "%s"%(str(log))) 
Example #9
Source File: libvirt_eventfilter.py    From masakari with Apache License 2.0 4 votes vote down vote up
def syslogout(msg, logLevel=syslog.LOG_DEBUG, logFacility=syslog.LOG_USER):

    # Output to the syslog.
    arg0 = os.path.basename(sys.argv[0])
    host = socket.gethostname()

    logger = logging.getLogger()
    logger.setLevel(logging.DEBUG)

    f = "%(asctime)s " + host + \
        " %(module)s(%(process)d): %(levelname)s: %(message)s"

    formatter = logging.Formatter(fmt=f, datefmt='%b %d %H:%M:%S')

    fh = logging.FileHandler(
        filename='/var/log/masakari/masakari-instancemonitor.log')
    fh.setLevel(logging.DEBUG)
    fh.setFormatter(formatter)

    logger.addHandler(fh)

    if logLevel == syslog.LOG_DEBUG:
        logger.debug(msg)
    elif logLevel == syslog.LOG_INFO or logLevel == syslog.LOG_NOTICE:
        logger.info(msg)
    elif logLevel == syslog.LOG_WARNING:
        logger.warn(msg)
    elif logLevel == syslog.LOG_ERR:
        logger.error(msg)
    elif logLevel == syslog.LOG_CRIT or \
            logLevel == syslog.LOG_ALERT or \
            logLevel == syslog.LOG_EMERGE:
        logger.critical(msg)
    else:
        logger.debug(msg)

    logger.removeHandler(fh)

#################################
# Function name:
#   virEventFilter
#
# Function overview:
#   Filter events from libvirt.
#
# Argument:
#   eventID   : EventID
#   eventType : Event type
#   detail    : Event name
#   uuID      : UUID
#
# Return value:
#   None
#
#################################