Python syslog.LOG_NOTICE Examples

The following are 15 code examples of syslog.LOG_NOTICE(). 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: NotifySyslog.py    From apprise with MIT License 6 votes vote down vote up
def send(self, body, title='', notify_type=NotifyType.INFO, **kwargs):
        """
        Perform Syslog Notification
        """

        _pmap = {
            NotifyType.INFO: syslog.LOG_INFO,
            NotifyType.SUCCESS: syslog.LOG_NOTICE,
            NotifyType.FAILURE: syslog.LOG_CRIT,
            NotifyType.WARNING: syslog.LOG_WARNING,
        }

        # Always call throttle before any remote server i/o is made
        self.throttle()
        try:
            syslog.syslog(_pmap[notify_type], body)

        except KeyError:
            # An invalid notification type was specified
            self.logger.warning(
                'An invalid notification type '
                '({}) was specified.'.format(notify_type))
            return False

        return True 
Example #2
Source File: NotifySyslog.py    From bazarr with GNU General Public License v3.0 6 votes vote down vote up
def send(self, body, title='', notify_type=NotifyType.INFO, **kwargs):
        """
        Perform Syslog Notification
        """

        _pmap = {
            NotifyType.INFO: syslog.LOG_INFO,
            NotifyType.SUCCESS: syslog.LOG_NOTICE,
            NotifyType.FAILURE: syslog.LOG_CRIT,
            NotifyType.WARNING: syslog.LOG_WARNING,
        }

        # Always call throttle before any remote server i/o is made
        self.throttle()
        try:
            syslog.syslog(_pmap[notify_type], body)

        except KeyError:
            # An invalid notification type was specified
            self.logger.warning(
                'An invalid notification type '
                '({}) was specified.'.format(notify_type))
            return False

        return True 
Example #3
Source File: test_syslog.py    From Safejumper-for-Desktop with GNU General Public License v2.0 5 votes vote down vote up
def test_emitCustomPriorityOverridesError(self):
        """
        L{SyslogObserver.emit} uses the value of the C{'syslogPriority'} key if
        it is specified even if the event dictionary represents an error.
        """
        self.observer.emit({
                'message': ('hello, world',), 'isError': True, 'system': '-',
                'syslogPriority': stdsyslog.LOG_NOTICE,
                'failure': Failure(Exception("bar"))})
        self.assertEqual(
            self.events,
            [(stdsyslog.LOG_NOTICE, '[-] hello, world')]) 
Example #4
Source File: logging.py    From pycopia with Apache License 2.0 5 votes vote down vote up
def notice(msg):
    syslog.syslog(syslog.LOG_NOTICE, _encode(msg)) 
Example #5
Source File: logging.py    From pycopia with Apache License 2.0 5 votes vote down vote up
def notice(msg):
    syslog.syslog(syslog.LOG_NOTICE, _encode(msg)) 
Example #6
Source File: logging.py    From pycopia with Apache License 2.0 5 votes vote down vote up
def loglevel_notice():
    loglevel(syslog.LOG_NOTICE) 
Example #7
Source File: test_syslog.py    From learn_python3_spider with MIT License 5 votes vote down vote up
def test_emitCustomPriorityOverridesError(self):
        """
        L{SyslogObserver.emit} uses the value of the C{'syslogPriority'} key if
        it is specified even if the event dictionary represents an error.
        """
        self.observer.emit({
                'message': ('hello, world',), 'isError': True, 'system': '-',
                'syslogPriority': stdsyslog.LOG_NOTICE,
                'failure': Failure(Exception("bar"))})
        self.assertEqual(
            self.events,
            [(stdsyslog.LOG_NOTICE, '[-] hello, world')]) 
Example #8
Source File: test_formats.py    From glog-cli with Apache License 2.0 5 votes vote down vote up
def test_get_log_level_from_code(self):
        self.assertEquals('CRITICAL', LogLevel.find_by_syslog_code(syslog.LOG_CRIT)['name'])
        self.assertEquals('WARNING', LogLevel.find_by_syslog_code(syslog.LOG_WARNING)['name'])
        self.assertEquals('DEBUG', LogLevel.find_by_syslog_code(syslog.LOG_DEBUG)['name'])
        self.assertEquals('INFO', LogLevel.find_by_syslog_code(syslog.LOG_INFO)['name'])
        self.assertEquals('ERROR', LogLevel.find_by_syslog_code(syslog.LOG_ERR)['name'])
        self.assertEquals('NOTICE', LogLevel.find_by_syslog_code(syslog.LOG_NOTICE)['name'])
        self.assertEquals('', LogLevel.find_by_syslog_code(9999)['name']) 
Example #9
Source File: test_formats.py    From glog-cli with Apache License 2.0 5 votes vote down vote up
def test_get_log_level_code(self):
        self.assertEquals(syslog.LOG_CRIT, LogLevel.find_by_level_name('CRITICAL'))
        self.assertEquals(syslog.LOG_WARNING, LogLevel.find_by_level_name('WARNING'))
        self.assertEquals(syslog.LOG_DEBUG, LogLevel.find_by_level_name('DEBUG'))
        self.assertEquals(syslog.LOG_INFO, LogLevel.find_by_level_name('INFO'))
        self.assertEquals(syslog.LOG_ERR, LogLevel.find_by_level_name('ERROR'))
        self.assertEquals(syslog.LOG_NOTICE, LogLevel.find_by_level_name('NOTICE'))
        self.assertIsNone(LogLevel.find_by_level_name('UNKNOWN')) 
Example #10
Source File: test_syslog.py    From python-for-android with Apache License 2.0 5 votes vote down vote up
def test_emitCustomPriorityOverridesError(self):
        """
        L{SyslogObserver.emit} uses the value of the C{'syslogPriority'} key if
        it is specified even if the event dictionary represents an error.
        """
        self.observer.emit({
                'message': ('hello, world',), 'isError': True, 'system': '-',
                'syslogPriority': stdsyslog.LOG_NOTICE,
                'failure': Failure(Exception("bar"))})
        self.assertEqual(
            self.events,
            [(stdsyslog.LOG_NOTICE, '[-] hello, world')]) 
Example #11
Source File: rodi-1.8.py    From Aquamonitor with GNU Lesser General Public License v3.0 5 votes vote down vote up
def Close_valve():
    Alert("Closing the RO/DI valve", syslog.LOG_NOTICE)
    try:
        urllib2.urlopen("http://192.168.0.150/set.cmd?user=admin+pass=12345678+cmd=setpower+p61=0", timeout = 10)
        time.sleep(5)
    except urllib2.URLError as e:
        Send_alert("Cannot communicate with valve: " + type(e), syslog.LOG_ERR) 
Example #12
Source File: rodi-1.8.py    From Aquamonitor with GNU Lesser General Public License v3.0 5 votes vote down vote up
def Open_valve():
    if Refilling() == True:
        Alert("RO/DI Valve already opened",syslog.LOG_WARNING)
        sys.exit(5)
    else:
        Alert("Opening the RO/DI valve",syslog.LOG_NOTICE)
        try:
            urllib2.urlopen("http://192.168.0.150/set.cmd?user=admin+pass=12345678+cmd=setpower+p61=1", timeout = 10)
            time.sleep(5)
        except urllib2.URLError as e:
            Send_alert("Cannot communicate with valve: " + type(e), syslog.LOG_ERR)
        time.sleep(VALVE_CHGSTATE_TIMER) 
Example #13
Source File: aquamonitor-1.8.py    From Aquamonitor with GNU Lesser General Public License v3.0 5 votes vote down vote up
def Alert(message, probe):                                                    # In any event of an alert, inform through log, mail & pushover
    global Alarms
    Alarms[probe] = datetime.now()                                            # set a timestamp for recurring alarm cooldown and alert
    if probe == "WATER_LEAK_DETECTOR_1" or probe == "WATER_LEAK_DETECTOR_2":
        Send_alert(message,syslog.LOG_EMERG)
    elif probe == "FLOATSW_HIGH_WL":
        Send_alert(message,syslog.LOG_ERR)
    elif probe == "FLOATSW_LOW_WL":
        Send_alert(message,syslog.LOG_NOTICE) 
Example #14
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
#
################################# 
Example #15
Source File: formats.py    From bonfire with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
def tail_format(fields=["source", "facility", "line", "module"], color=True):
    def format(entry):
        message_text = entry.message
        timestamp = entry.timestamp.to('local')
        level_string = entry.level

        log_color = 'green'
        log_background = None

        if entry.level == syslog.LOG_CRIT:
            log_color = 'white'
            log_background = 'on_red'
            level_string = "CRITICAL"
        elif entry.level == syslog.LOG_ERR:
            log_color = 'red'
            level_string = "ERROR   "
        elif entry.level == syslog.LOG_WARNING:
            log_color = 'yellow'
            level_string = "WARNING "
        elif entry.level == syslog.LOG_NOTICE:
            log_color = 'green'
            level_string = "NOTICE  "
        elif entry.level == syslog.LOG_INFO:
            log_color = 'green'
            level_string = "INFO    "
        elif entry.level == syslog.LOG_DEBUG:
            log_color = 'blue'
            level_string = "DEBUG   "

        if message_text:
            message_text = " " + message_text + " #"

        local_fields = list(fields)
        if "message" in local_fields:
            local_fields.remove("message")

        field_text = map(lambda f: "{}:{}".format(f, entry.message_dict.get(f, "")), local_fields)

        log = "{level_string}[{timestamp}]{message_text} {field_text}".format(
            timestamp=timestamp.format("YYYY-MM-DD HH:mm:ss.SS"),
            level_string=level_string,
            message_text=message_text,
            field_text="; ".join(field_text))
        if color:
            return colored(log, log_color, log_background)
        else:
            return log

    return format