Python syslog.syslog() Examples

The following are 30 code examples of syslog.syslog(). 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: run_containers.py    From container-agent with Apache License 2.0 10 votes vote down vote up
def main():
    if len(sys.argv) > 2:
        Fatal('usage: %s [containers.yaml]' % sys.argv[0])

    if len(sys.argv) == 2:
        with open(sys.argv[1], 'r') as fp:
            config = yaml.load(fp)
    else:
        config = yaml.load(sys.stdin)

    syslog.openlog(PROGNAME)
    LogInfo('processing container manifest')

    CheckVersion(config)

    all_volumes = LoadVolumes(config.get('volumes', []))
    user_containers = LoadUserContainers(config.get('containers', []),
                                         all_volumes)
    CheckGroupWideConflicts(user_containers)

    if user_containers:
        infra_containers = LoadInfraContainers(user_containers)
        RunContainers(infra_containers + user_containers) 
Example #2
Source File: user.py    From cve-portal with GNU Affero General Public License v3.0 7 votes vote down vote up
def change_email_request():
    form = form_class.ChangeEmailForm()
    if form.validate_on_submit():
        if current_user.verify_password(form.password.data):
            new_email = escape(form.email.data)
            token = current_user.generate_email_change_token(new_email)
            send_email(new_email,
                       'CVE-PORTAL -- Confirm your email address',
                       '/emails/change_email',
                       user=current_user,
                       token=token)
            syslog.syslog(syslog.LOG_WARNING,
                          "User as requested an email change: Old:" + current_user.email + " New: " + form.email.data)
            flash('An email with instructions to confirm your new email address has been sent to you.', 'info')
            return redirect(url_for('main.index'))
        else:
            flash('Invalid email or password.', 'danger')
    return render_template("auth/change_email.html", form=form) 
Example #3
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 #4
Source File: logs.py    From alertlib with MIT License 6 votes vote down vote up
def send_to_logs(self):
        """Send to logs: either GAE logs (for appengine) or syslog."""
        if not self._passed_rate_limit('logs'):
            return self

        logging.log(self.severity, self.message)

        # Also send to syslog if we can.
        if not self._in_test_mode():
            try:
                syslog_priority = self._mapped_severity(_LOG_TO_SYSLOG)
                syslog.syslog(syslog_priority,
                              base.handle_encoding(self.message))
            except (NameError, KeyError):
                pass

        return self 
Example #5
Source File: logger.py    From clonedigger with GNU General Public License v3.0 6 votes vote down vote up
def make_logger(method='print', threshold=LOG_DEBUG, sid=None, output=None):
    """return a logger for the given method
    
    known methods are 'print', 'eprint' and syslog'
    """
    if method == 'print':
        if output is None:
            output = sys.stdout
        return PrintLogger(threshold, output, sid=sid)
    elif method == 'eprint':
        return PrintLogger(threshold, sys.stderr, sid=sid)
    elif method == 'syslog':
        return SysLogger(threshold, sid)
    elif method == 'file':
        if not output:
            raise ValueError('No logfile specified')
        else:
            logfile = open(output, 'a')
            return PrintLogger(threshold, logfile, sid=sid)
    else:
        raise ValueError('Unknown logger method: %r' % method) 
Example #6
Source File: user.py    From cve-portal with GNU Affero General Public License v3.0 6 votes vote down vote up
def change_pgp():
    form = form_class.ChangePGPForm()
    if form.validate_on_submit():
        if current_user.verify_password(form.password.data):
            ki = gpg.import_keys(form.pgp.data)
            if not ki.fingerprints:
                fingerp = "--- NO VALID PGP ---"
            else:
                fingerp = ki.fingerprints[0]
            current_user.pgp = form.pgp.data
            current_user.fingerprint = fingerp
            models.db.session.add(current_user)
            models.db.session.commit()
            flash('Your PGP key has been updated.', 'info')
            syslog.syslog(syslog.LOG_INFO, "User Changed his PGP: " + current_user.email)
            return redirect(url_for('main.index'))
        else:
            flash('Invalid password.', 'danger')
    return render_template("auth/change_pgp.html", form=form) 
Example #7
Source File: fwaudit.py    From fwaudit with GNU General Public License v2.0 6 votes vote down vote up
def startup_message():
    '''Show initial status information to user and logs.

    Send initial message to syslog, if --syslog specified.
    Send initial message to eventlog, if --eventlog specified.
    Send initial message to logfile, if --logfile specified.
    '''
    print()
    log(APP_METADATA['full_name'] + ' Version ' + APP_METADATA['version'])
    log('Copyright (C) ' + APP_METADATA['copyright'] + ' ' +
        APP_METADATA['full_author'] + '. All rights reserved.')
    if app_state['syslog_mode']:
        syslog_send(APP_METADATA['short_name'] + ': starting...')
    if app_state['eventlog_mode']:
        eventlog_send(APP_METADATA['short_name'] + ': starting...')
    print() 
Example #8
Source File: test_log.py    From oslo.log with Apache License 2.0 5 votes vote down vote up
def test_emit_exception(self):
        logger = log.getLogger('nova-exception.foo')
        local_context = _fake_new_context()
        try:
            raise Exception("Some exception")
        except Exception:
            logger.exception("Foo", context=local_context)
        self.assertEqual(
            mock.call(mock.ANY, CODE_FILE=mock.ANY,
                      CODE_FUNC='test_emit_exception',
                      CODE_LINE=mock.ANY, LOGGER_LEVEL='ERROR',
                      LOGGER_NAME='nova-exception.foo', PRIORITY=3,
                      SYSLOG_FACILITY=syslog.LOG_USER,
                      SYSLOG_IDENTIFIER=mock.ANY,
                      REQUEST_ID=mock.ANY,
                      EXCEPTION_INFO=mock.ANY,
                      EXCEPTION_TEXT=mock.ANY,
                      PROJECT_NAME='mytenant',
                      PROCESS_NAME='MainProcess',
                      THREAD_NAME='MainThread',
                      USER_NAME='myuser'),
            self.journal.send.call_args)
        args, kwargs = self.journal.send.call_args
        self.assertEqual(len(args), 1)
        self.assertIsInstance(args[0], str)
        self.assertIsInstance(kwargs['CODE_LINE'], int)
        self.assertIsInstance(kwargs['PRIORITY'], int)
        self.assertIsInstance(kwargs['SYSLOG_FACILITY'], int)
        del kwargs['CODE_LINE'], kwargs['PRIORITY'], kwargs['SYSLOG_FACILITY']
        for key, arg in kwargs.items():
            self.assertIsInstance(key, str)
            self.assertIsInstance(arg, (bytes, str)) 
Example #9
Source File: touch.py    From rpi-5inch-hdmi-touchscreen-driver with MIT License 5 votes vote down vote up
def read_pointercal_calib_file():
    # a1..a7 are touch panel calibration coefficients
    a1=1 #0
    a2=0 #1
    a3=0 #2
    a4=0 #3
    a5=1 #4
    a6=0 #5
    a7=1 #6
    # scx, scy are screen dimensions at moment of performing calibration
    scx=0
    scy=0
    # file is built from single line, values are space separated, there is 9 values
    try:
        with open(calib_file,'r') as ff:
            a1,a2,a3,a4,a5,a6,a7,scx,scy = ff.readline().split()
    except:
        syslog.syslog(syslog.LOG_WARNING,'TouchDriver: No calibration file: {0}'.format(calib_file))
        print("No tslib calibration file, using defaults.")

    print("A1..A7: ",a1,a2,a3,a4,a5,a6,a7)
    print("Screen dims: X=",scx," Y=", scy)
    syslog.syslog(syslog.LOG_INFO,'TouchDriver: Using calibration data A1..A7: {0} {1} {2} {3} {4} {5} {6}'.format(a1,a2,a3,a4,a5,a6,a7))
    return [int(a1),int(a2),int(a3),int(a4),int(a5),int(a6),int(a7)]
    
    

# Wait and find devices 
Example #10
Source File: syslog_writer.py    From radish with MIT License 5 votes vote down vote up
def syslog_writer_before_each_feature(self, feature):
        import syslog

        syslog.syslog(
            "begin feature {}:{} {}".format(
                self.marker, feature.id, feature.short_description
            )
        ) 
Example #11
Source File: syslog_writer.py    From radish with MIT License 5 votes vote down vote up
def syslog_writer_before_each_step(self, step):
        import syslog

        syslog.syslog(
            "begin step {}:{}.{}.{} {} {}".format(
                self.marker,
                step.feature.id,
                step.scenario.id,
                step.id,
                step.keyword,
                step.text,
            )
        ) 
Example #12
Source File: syslog_writer.py    From radish with MIT License 5 votes vote down vote up
def __init__(self, marker):
        self.marker = marker
        # import syslog only if the extension got loaded
        # but not if the module got loaded.
        import syslog  # noqa

        before.all()(self.syslog_writer_before_all)
        before.each_feature()(self.syslog_writer_before_each_feature)
        before.each_scenario()(self.syslog_writer_before_each_scenario)
        before.each_step()(self.syslog_writer_before_each_step)
        after.all()(self.syslog_writer_after_all)
        after.each_feature()(self.syslog_writer_after_each_feature)
        after.each_scenario()(self.syslog_writer_after_each_scenario)
        after.each_step()(self.syslog_writer_after_each_step) 
Example #13
Source File: syslog_writer.py    From radish with MIT License 5 votes vote down vote up
def syslog_writer_before_all(self, features):
        import syslog

        syslog.openlog("radish")
        syslog.syslog("begin run {}".format(self.marker)) 
Example #14
Source File: syslog_writer.py    From radish with MIT License 5 votes vote down vote up
def syslog_writer_after_all(self, features):
        import syslog

        syslog.syslog("end run {}".format(self.marker))
        syslog.closelog() 
Example #15
Source File: syslog_writer.py    From radish with MIT License 5 votes vote down vote up
def syslog_writer_after_each_scenario(self, scenario):
        import syslog

        syslog.syslog(
            "end scenario {}:{}.{} {}".format(
                self.marker,
                scenario.feature.id,
                scenario.id,
                scenario.short_description,
            )
        ) 
Example #16
Source File: syslog_writer.py    From radish with MIT License 5 votes vote down vote up
def syslog_writer_after_each_step(self, step):
        import syslog

        syslog.syslog(
            "{} step {}:{}.{}.{} {} {}".format(
                step.state.name.lower(),
                self.marker,
                step.feature.id,
                step.scenario.id,
                step.id,
                step.keyword,
                step.text,
            )
        ) 
Example #17
Source File: logger.py    From clonedigger with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, threshold, sid=None, encoding='UTF-8'):
        import syslog
        AbstractLogger.__init__(self, threshold)
        if sid is None:
            sid = 'syslog'
        self.encoding = encoding
        syslog.openlog(sid, syslog.LOG_PID) 
Example #18
Source File: cloud_watch_client.py    From cloudwatch-mon-scripts-python with Apache License 2.0 5 votes vote down vote up
def log_error(message, use_syslog):
    if use_syslog:
        syslog.syslog(syslog.LOG_ERR, message)
    else:
        print('ERROR: ' + message, file=sys.stderr) 
Example #19
Source File: logging.py    From pycopia with Apache License 2.0 5 votes vote down vote up
def __exit__(self, extype, exvalue, traceback):
        syslog.setlogmask(self._oldloglevel) 
Example #20
Source File: logging.py    From pycopia with Apache License 2.0 5 votes vote down vote up
def __enter__(self):
        self._oldloglevel = syslog.setlogmask(syslog.LOG_UPTO(self._level)) 
Example #21
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 #22
Source File: logging.py    From pycopia with Apache License 2.0 5 votes vote down vote up
def loglevel_error():
    loglevel(syslog.LOG_ERR) 
Example #23
Source File: logging.py    From pycopia with Apache License 2.0 5 votes vote down vote up
def loglevel_warning():
    loglevel(syslog.LOG_WARNING) 
Example #24
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 #25
Source File: logging.py    From pycopia with Apache License 2.0 5 votes vote down vote up
def loglevel_info():
    loglevel(syslog.LOG_INFO) 
Example #26
Source File: logging.py    From pycopia with Apache License 2.0 5 votes vote down vote up
def loglevel_debug():
    loglevel(syslog.LOG_DEBUG) 
Example #27
Source File: logging.py    From pycopia with Apache License 2.0 5 votes vote down vote up
def loglevel(level):
    global _oldloglevel
    _oldloglevel = syslog.setlogmask(syslog.LOG_UPTO(level)) 
Example #28
Source File: logging.py    From pycopia with Apache License 2.0 5 votes vote down vote up
def emergency(msg):
    syslog.syslog(syslog.LOG_EMERG, _encode(msg))

### set loglevels 
Example #29
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 #30
Source File: logging.py    From pycopia with Apache License 2.0 5 votes vote down vote up
def critical(msg):
    syslog.syslog(syslog.LOG_CRIT, _encode(msg))