istio默认会进行日志的记录,但是仅仅记录到服务、以及服务之间调用的信息,不记录业务日志。

如:

所以需要添加业务日志记录。

1.python引入package

fluent
msgpack

2.代码中引入相关类,并连接fluent服务

1)Event-Based Interface 发送fluent日志 是对FluentSender的包装

from fluent import sender, event

logger = sender.FluentSender('fluent-python', host='192.168.181.99', port=30224)

对应方法中添加日志记录

2)Python logging.Handler interface 定义日志格式 发送fluent日志

import msgpack
from io import BytesIO
import logging
from fluent import handler

def overflow_handler(pendings):
unpacker = msgpack.Unpacker(BytesIO(pendings))
for unpacked in unpacker:
print(unpacked)

custom_format = {
'host': '%(hostname)s',
'where': '%(module)s.%(funcName)s',
'type': '%(levelname)s',
'stack_trace': '%(exc_text)s'
}

logging.basicConfig(level=logging.INFO)
l = logging.getLogger('fluent.test')

#remote fluent服务

#
h = handler.FluentHandler('fluent-python.log',
host='fluentd-es.logging', port=24224,
buffer_overflow_handler=overflow_handler)

# 本地调用fluent服务
h = handler.FluentHandler('fluent-python.log', host='192.168.181.99', port=30224, buffer_overflow_handler=overflow_handler)
formatter = handler.FluentRecordFormatter(custom_format)
h.setFormatter(formatter)
l.addHandler(h)

对应方法中添加日志记录

3.fluent ui 展现情况

1)event记录日志

2)自定义日志格式

4.事例项目

istio事例项目(jeager-fluent分支)

https://github.com/jiuchongxiao/istio-python-hello-jaeger.git

没加istio事例项目

https://github.com/jiuchongxiao/python-fluent-example.git

python添加fluent日志记录的更多相关文章

  1. python添加fluent日志记录-aop

    python添加fluent日志,aop实现 1.配置fluent相关信息 fluent_config.ini fluent_config.ini [fluent.aop] #is support f ...

  2. springboot添加fluent日志记录

    istio默认会进行日志的记录,但是仅仅记录到服务.以及服务之间调用的信息,不记录业务日志. 如: 所以需要添加业务日志记录. 1.引入依赖 <dependency>     <gr ...

  3. Python开发之日志记录模块:logging

    1 引言 最近在开发一个应用软件,为方便调试和后期维护,在代码中添加了日志,用的是Python内置的logging模块,看了许多博主的博文,颇有所得.不得不说,有许多博主大牛总结得确实很好.似乎我再写 ...

  4. spring/spirng boot添加fluent日志-aop

    此项目以aop的形式添加fluent 日志 sample介绍 spring-mvc-aop-helloworld 为spring mvc aop condition toolcommontest 为s ...

  5. .NET Worker Service 添加 Serilog 日志记录

    前面我们了解了 .NET Worker Service 的入门知识[1] 和 如何优雅退出 Worker Service [2],今天我们接着介绍一下如何为 Worker Service 添加 Ser ...

  6. Yii2如何添加sql日志记录的配置信息

    在使用Yii2框架的时候,常常会出现没有sql日志记录的问题.在代码里一句一句的打印sql语句也不现实.所以就要用文件记录起来. 在 config/web.php 里面的 log配置中增加如下配置 [ ...

  7. Python中的日志记录方案-logging模块&loguru模块

    原文链接 原创: 崔庆才 在 Python 中,一般情况下我们可能直接用自带的 logging 模块来记录日志,包括我之前的时候也是一样.在使用时我们需要配置一些 Handler.Formatter ...

  8. .net 项目如何添加log4net日志记录

    1.在项目根目录新建文件log4net.config,此文件中的节点解释还请自动百度. 文件实例: <?xml version="1.0"?><configura ...

  9. python工具之日志记录

    ''' 写日志类 日志存放目录为当前应用程序的目录下的log目录中 日志产生规则:每小时产生一个文件 write by :wujf 2017-02-24 ''' import sys import o ...

随机推荐

  1. 主流浏览器 Cookie 的大小

    目前测试的两种浏览器:Chrome 和 IE . 环境:IIS 7.5 只创建了站点,未做任何配置. Chrome : v36.0.1985.143 m 单个 Cookie 的长度为 4069 个字符 ...

  2. vue练习

    <div id="app"> <div> <span>姓名</span> <input type="text&quo ...

  3. oracle 连接池参数

    后来排查出数据库监听异常,发现是ORA-12519拒绝错误.后来发现是数据的连接池达到的极致. 具体解决方案如下: --首先检查process和session的使用情况,在sqlplus里面查看. S ...

  4. ofstream和ifstream

    ofstream(输出流)是从内存到硬盘,ifstream(输入流)是从硬盘到内存. //#include<iostream> #include<fstream> using ...

  5. opencv批量读取图片

    #include<opencv2/opencv.hpp>using namespace cv;using namespace std;int main(){    int num=4;// ...

  6. 使用openshit在ubuntu14.04下一键部署openstack(juno版本)

    一.基本介绍 本实验是在vmware workstation上虚拟机ubuntu14.04(64bit,desktop)上部署openstack(Juno版本).采用的工具是openshit.open ...

  7. Codeforces Round #499 (Div. 2) D. Rocket题解

    题目: http://codeforces.com/contest/1011/problem/D This is an interactive problem. Natasha is going to ...

  8. 1.3.5、CDH 搭建Hadoop在安装之前(端口---Cloudera Search使用的端口)

    Cloudera Search使用的端口 在下表中,每个端口的“ 访问要求”列通常是“内部”或“外部”.在此上下文中,“内部”表示端口仅用于组件之间的通信; “外部”表示该端口可用于内部或外部通信. ...

  9. tomcat中的类加载机制

    Tomcat中的类加载机制符合JVM推荐的双亲委派模型,关于JVM的类加载机制不多说,网上很多资料. 1. Tomcat类加载器过程. tomcat启动初始化阶段创建几个类加载器: private v ...

  10. 修改app工程名 Android Studio

    1.关掉AndroidStudio,在原项目最外层文件夹和内部xxx.iml上直接重新命名, 2.然后重新打开AndroidStudio,加载项目, 3.最后