一个方便日志发送到statuscope的包

statuscope的Python项目详细描述


python包

pypi上的python包的源代码

安装和更新

sudo pip3 install --upgrade statuscope

示例

这是这个包裹的使用示例。

importargparseimporttimeimportsysimportrandomfromstatuscope.loggerimportLoggerfromstatuscope.loggerimportLoggerConfigif__name__=='__main__':parser=argparse.ArgumentParser(description='Sends logs to Statuscope.io')parser.add_argument('-t','--token',help='API token or task-specific token',required=True)parser.add_argument('-i','--task_id',help='Task ID',required=True)args=parser.parse_args()# Create a logger configuration object and enable logslog_config=LoggerConfig()log_config.enable_logs()# Set the component that these logs belong to# Note that this is a global setting and it can be overridden on each (debug|info|warning|error|alert) calllog_config.set_component('test')log_sender=Logger(args.token,args.task_id,log_config)log_sender.start()# We'll generate some silly log messages because test data is usually so boringobjects=['plane','bike','book','icecream','dog']colors=['yellow','green','red','black','pink','white']components=['auth','backend','frontend','db','payment']severities=['debug','info','warning','error','alert']counter=0whileTrue:counter=counter+1try:time.sleep(1)severity=random.choice(severities)component=random.choice(components)color=random.choice(colors)object=random.choice(objects)ifseverity=='debug':log_sender.debug("Log %s: I have a %s%s"%(counter,color,object),component)elifseverity=='info':log_sender.info("Log %s: I have a %s%s"%(counter,color,object),component)elifseverity=='warning':log_sender.warn("Log %s: I have a %s%s"%(counter,color,object),component)elifseverity=='error':log_sender.error("Log %s: I have a %s%s"%(counter,color,object),component)elifseverity=='alert':log_sender.alert("Log %s: I have a %s%s"%(counter,color,object),component)exceptKeyboardInterrupt:print("Ctrl-C received, exiting...")log_sender.flush()try:log_sender.join()exceptExceptionase:print(str(e))sys.exit()

然后要更新日志任务,

python3 test.py --token cfa0d2ed --task_id QbZJjD2u3uzFvTYAM

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
“java.lang.TypeNotPresentException:键入org.hibernate.SessionFactory不存在”   java如何添加两个内容为number的字符数组?   java变量未初始化我必须设置一个变量,而不是仅仅在if语句中添加它吗?   在Java中,main和constructor可以一起在一个类中吗   安卓在java中拖动多个按钮视图   字符串读写文件Java空空间   java在使用Moshi JsonAdapter反序列化时丢失字段值。工厂   如何在Java中使用for循环和扫描程序添加数组   在java andriod中使用notifyDataSetChanged()后,安卓 Arraylist未重新填充   java枚举类型中的方法能否更改枚举实例的状态?   java pbkdf2盐渍哈希密码验证   java Maven jgit JDWP传输错误   基于浏览web内容的java用户行为分析   java为什么我在STS中遇到编译错误   java Spring引导REST获取HTTPConnectionURL的参数   在JFrame中使用JPanel的java无法正确调整大小或移动   java泛型遗留兼容性问题   java将动态表单上的类对象传递给意图对象