def log(config, message, severity=usyslog.S_INFO): host = config['syslog']['host'] ts = get_timestamp(config) client = usyslog.UDPClient(ip=host) client.log(severity, message) client.close()
def sendLog(level, message, mod): t = TYPE_STR[level] print("[SYSLOG %s] " % t + mod + ": " + message) if sysCONF['host'] is not '0.0.0.0': if int(sysCONF['tcp']) == 0: u = usyslog.UDPClient(ip=sysCONF['host'], port=sysCONF['port']) if level == ALERT: u.alert(message, mod, sysCONF['TZ']) elif level == CRIT: u.critical(message, mod, sysCONF['TZ']) elif level == ERR: u.error(message, mod, sysCONF['TZ']) elif level == WARN: u.warning(message, mod, sysCONF['TZ']) elif level == NOTICE: u.notice(message, mod, sysCONF['TZ']) elif level == INFO: u.info(message, mod, sysCONF['TZ']) elif level == DEBUG: u.debug(message, mod, sysCONF['TZ']) else: u.log(usyslog.S_EMERG, message, mod, sysCONF['TZ']) u.close() elif int(sysCONF['tcp']) == 1: u = usyslog.TCPClient(ip=sysCONF['host'], port=sysCONF['port']) if level == ALERT: u.alert(message, mod, sysCONF['TZ']) elif level == CRIT: u.critical(message, mod, sysCONF['TZ']) elif level == ERR: u.error(message, mod, sysCONF['TZ']) elif level == WARN: u.warning(message, mod, sysCONF['TZ']) elif level == NOTICE: u.notice(message, mod, sysCONF['TZ']) elif level == INFO: u.info(message, mod, sysCONF['TZ']) elif level == DEBUG: u.debug(message, mod, sysCONF['TZ']) else: u.log(usyslog.S_EMERG, message, mod, sysCONF['TZ']) u.close()
if _NETWORK_MODULE_LOADED: wlan = network.WLAN(network.STA_IF) wlan.active(True) if not wlan.isconnected(): print('Connecting to WLAN...') wlan.connect(WLAN_SSID, WLAN_PSK) while not wlan.isconnected(): time.sleep_ms(500) print(' Waiting for WLAN to connect...') print('WLAN Connected:') print(' Network configuration:', wlan.ifconfig()) print('Starting syslog tests...') # Test non-default facility s = usyslog.UDPClient(ip=SYSLOG_SERVER_IP, facility=usyslog.F_LOCAL4) s.info('LOCAL4:Info!') # Test other methods s = usyslog.UDPClient(ip=SYSLOG_SERVER_IP) s.alert('Testing a message with alert severity') s.critical('This is a non critical test message!') s.error('In case of an error, you can use this severity.') s.debug('Debug messages can get annoying in production environments!') s.info( 'Informational messages are just slightly less "severe" than debug messages' ) s.notice('Noticed this? Nevermind!') s.warning('This is my last warning!') s.log(usyslog.S_EMERG, 'This is an emergency! Lets hope all prior tests did pass succesfully!')
def __init__(self, config) : host = config['host'] port = config['port'] ## TODO add support for the facility self._client = usyslog.UDPClient(host, port)