def test_getLogger_text(self): logger = mylogging.getLogger('test_getLogger_text', fmt='text') logger.info('This is text test.') log = self.stderr.getvalue() datetime.strptime(log[0:25], '%Y-%m-%dT%H:%M:%S+09:00') self.assertEqual(' [INFO] This is text test.\n', log[25:])
def test_getLogger_json(self): logger = mylogging.getLogger('test_getLogger_json', fmt='json') logger.info('This is json test.') import json log = json.loads(self.stderr.getvalue()) datetime.strptime(log['time'], '%Y-%m-%dT%H:%M:%S+09:00') del log['time'] expect = { 'level': 'info', 'message': 'This is json test.', 'name': 'test_getLogger_json' } self.assertDictEqual(log, expect)
def start_cat_alarm(config): relay_pin = 5 Pin(relay_pin, Pin.OUT).value(0) # avoid being on at start wdt = WDT(timeout=1200) loop = asyncio.get_event_loop() loop.set_exception_handler(global_exception_handler) MyWifi(config['ssid'], config['password'], event_loop=loop, led_pin=2) dht_obj = MyDHT(13, dht_type=DHT22, event_loop=loop) button_obj = MyPinIn(pin=14, pull=Pin.PULL_UP, active_state=0, event_loop=loop) pir_objs = (MyPinIn(pin=12, bounce_ms=5000, event_loop=loop), MyPinIn(pin=4, bounce_ms=5000, event_loop=loop)) cat_alarm = MyCatAlarm(button=button_obj, pirs=pir_objs, dht=dht_obj, event_loop=loop, config=config, wdt=wdt) mylogging.basicConfig(level=mylogging.INFO) log = mylogging.getLogger(__name__) app = mypicoweb.MyPicoWeb(__name__, button_obj=button_obj, cat_alarm=cat_alarm) app.add_url_rule('/', web_index) app.add_url_rule('/honk', web_honk) app.add_url_rule('/change', web_change_state) app.add_url_rule('/status', web_status) app.add_url_rule('/reboot', web_reboot) app.add_url_rule('/get_config', web_get_config) app.add_url_rule('/save_config', web_save_config) app.add_url_rule('/webrepl', web_repl) app.add_url_rule('/config', web_config) gc.collect() app.run(host="0.0.0.0", port=80, log=log, debug=True)
################################################## # AUTHOR : Yandi LI # CREATED_AT : 2015-09-15 # LAST_MODIFIED : 2015年11月14日 星期六 16时46分14秒 # USAGE : python core.py # PURPOSE : TODO ################################################## import mylogging import threading import multiprocessing import multiprocessing.queues as Queue import os, time import requests, json logging = mylogging.getLogger('Core') class FileIO(threading.Thread): """ Class that interacts with files. When initiated with read method, reads lines from a file with a given filename and inserts into its queue; When initiated with write method, read from its own queue and write to a file in system """ def __init__(self, filename, file_method='r', IOQueue=None, daemon=False, encode='utf-8', append_newline=True): """ @Parameters --------------------------
#! /usr/bin/env python3 import sys import mylogging mylogging.init() logger = mylogging.getLogger(__name__) if __name__ == '__main__': appname = sys.argv[0] logger.warning("Starting {} ...".format(appname)) logger.warning("Finish {}".format(appname))
import threading import Queue import os import mylogging try: tmp_path = os.path.dirname(os.path.realpath(__file__)) sys.path.append(tmp_path) from pynats import connection as natsconnection except Exception as e: for info in e.args: print info sys.exit(1) LOG = mylogging.getLogger() class MyNATSBase(threading.Thread): def __init__(self, natsurl, queue): threading.Thread.__init__(self) self._exit = False self._done = False self._natsurl = natsurl self._subscribes = [] self._connok = False self._queue = queue self._lock = threading.Lock() def on_message(self, msg): if self._queue is not None:
#!/usr/bin/env python #coding=utf-8 import sys, os, shutil import re, urllib, urllib2, json,redis import time,socket from lib import get_from_api from multiprocessing import Queue,Process,Pool import mylogging import Queue import threading from write_token import * flist = {} queue = Queue.Queue(maxsize = int(sys.argv[1])) log=mylogging.getLogger('fea') #获取图片信息 def getPicSize(pid): ''' Compute the width and height of a picture by its picture id >>> getPicSize('81f892c2jw1eq45l3wq3bj20u01hck12') (1080, 1920) ''' assert isinstance(pid,str) or isinstance(pid,unicode) str36='0123456789abcdefghijklmnopqrstuvwxyz' charMap = dict((s,i) for i,s in enumerate(str36)) if len(pid) < 32: return (0,0) w = charMap[pid[23]]*36*36 + charMap[pid[24]]*36 + charMap[pid[25]] h = charMap[pid[26]]*36*36 + charMap[pid[27]]*36 + charMap[pid[28]]
#!/usr/bin/env python #coding=utf-8 import sys import os import commands import shutil import mylogging import thread import threading import time from ServiceClient import * logger = mylogging.getLogger('k8sdeploy.log') ipList = [] mutex = threading.Lock() def config_kubectl(): homepath = os.environ['HOME'] configpath = os.path.join(homepath, ".kube") if not os.path.exists(configpath): print_log("configuring k8s deploy tool.") os.mkdir(configpath, 0755) deploy_dir = get_deploy_dir() logger.info("deploy_dir is:%s",deploy_dir) src_file = os.path.join(deploy_dir, "config") dst_file = os.path.join(configpath, "config") shutil.copyfile(src_file, dst_file) if not os.path.exists("/usr/bin/kubectl"): shutil.copyfile(deploy_dir + "/kubectl", "/usr/bin/kubectl") cmd = "chmod +x /usr/bin/kubectl" status,output = commands.getstatusoutput(cmd)
def __init__(self, logger_name="Recorder"): self.logger = mylogging.getLogger(logger_name)
#!/usr/bin/python # coding=UTF-8 # # Title: pingDevices.py # Author: Luc Fouin <*****@*****.**> # Date: 03/12/2014 # Info: check listed devices against last updated time to send notification for abnormal quiet devices from datetime import * import os import requests import yaml import mylogging logger = mylogging.getLogger(__name__) # Settings for the domoticz server domoticzserver = '127.0.0.1:8080' # URL of Free mobile SMS API smsAPIUrl = 'https://smsapi.free-mobile.fr/sendmsg' # get params from YAML file (name after this script .yaml) params = yaml.load(open(os.path.splitext(__file__)[0] + '.yaml')) smsAPIUser = params['smsAPIUser'] smsAPIPass = params['smsAPIPass'] devices = params['devices'] # function to send notification def sendNotification(msg) : r = requests.get(smsAPIUrl, params={u'user': smsAPIUser, u'pass': smsAPIPass, u'msg': msg}, verify=False)