celery的log如何传递给django,由django管理
celery自己管理log目录
celery worker --autoscale=4,1 --app=erebus.celeryapp:app -l info -f /home/admin/output/erebus/logs/worker.log -Q erebus,celery
celery beat --loglevel info --app erebus.celeryapp:app --logfile /home/admin/output/erebus/logs/beat.log
celery flower -A erebus.celeryapp:app --broker=sentinel://:password@ip:26379/6 --basic_auth=flower:flower,user:password
日志给django管理
配置EREBUS_WORKER_HIJACK_ROOT_LOGGER=False 参考配置的日志选项:http://docs.celeryproject.org/en/latest/userguide/configuration.html
django的日志配置:
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'verbose': {
# 后缀d表示数据格式是整数,s表示数据格式是字符串
'format': '[%(levelname)s] [%(asctime)s] [%(module)s] %(filename)s:%(lineno)d %(funcName)s '
'%(processName)s:[%(process)d] %(threadName)s:[%(thread)d] %(message)s'
# 'format': '{levelname} {asctime} {module} {process:d} {thread:d} {message}',
# 'style': '{',
},
'simple': {
'format': '[%(levelname)s] [%(asctime)s] %(message)s',
# 'format': '[%(asctime)s] %(message)s',
# 后缀d表示数据格式是整数,s表示数据格式是字符串
# 'format': '[%(levelname)s] [%(asctime)s] [%(module)s] %(filename)s:%(lineno)d %(funcName)s '
# '%(processName)s:[%(process)d] %(threadName)s:[%(thread)d] %(message)s',
# 'style': '{',
},
'standard': {
# 'format': '%(asctime)s [%(levelname)s] %(name)s: %(message)s',
'format': '{asctime} [{levelname:7}] {name:30}: {message}',
# 设置上面格式样式;{levelname:3}是告警级别,至少显示7个字符,少则补空格;多则正常显示
# 这里style选择{,是指{asctime}这种形式。
# 如果选择%,则是%(asctime)s这种形式。
# 还有一种选择,是$,是$asctime或${asctime}这种形式。
'style': '{',
# 设置时间格式
'datefmt': '%Y-%m-%d %H:%M:%S',
},
'operation': {
'format': '%(message)s'
}
},
# 'filters': {
# # 'special': {
# # '()': 'erebus.logging.SpecialFilter',
# # 'foo': 'bar',
# # },
# 'require_debug_true': {
# '()': 'django.utils.log.RequireDebugTrue',
# },
# },
# Handler是决定如何处理logger中每一条消息的引擎。它描述特定的日志行为,比如把消息输出到屏幕、文件或网络socket。
# 和 logger 一样,handler 也有日志级别的概念。如果一条日志记录的级别不匹配或者低于 handler 的日志级别,
# 对应的消息会被 handler 忽略。
'handlers': {
'default': {
# 'level': 'WARNING',
# 'class': 'logging.handlers.RotatingFileHandler',
# 'filename': '{}/default.log'.format(BASE_LOG_DIR),
# 'maxBytes': 1024*1024*5*20, # 5*20 MB
# 'maxBytes': 1024*5, # 5 KB
# 保留7天的日志,没份5M,5份大概是一个小时的日志内容,主要是kafka日志
# 'backupCount': int(5*1*24*7/20),
# 'formatter': 'standard',
'level': 'WARNING', # 忽略debug信息
'class': 'utils.graylog.graylog_django.GraylogHandler',
'app': 'erebus',
'file': 'app.log',
'host': GRAYLOG_HOST,
'port': GRAYLOG_PORT,
'localname': GRAYLOG_SOURCE,
},
'pipeline': {
# 'level': 'DEBUG',
# 'class': 'logging.handlers.RotatingFileHandler',
# 'filename': '{}/pipeline.log'.format(BASE_LOG_DIR),
# 'maxBytes': 1024*1024*5*20, # 5*20 MB
# 'maxBytes': 1024*5, # 5 KB
# 保留7天的日志,没份5M,5份大概是一个小时的日志内容,主要是kafka日志
# 'backupCount': int(5*1*24*7/20),
# 'formatter': 'standard',
'level': 'DEBUG', # 忽略debug信息
'class': 'utils.graylog.graylog_django.GraylogHandler',
'app': 'erebus',
'file': 'pipeline.log',
'host': GRAYLOG_HOST,
'port': GRAYLOG_PORT,
'localname': GRAYLOG_SOURCE,
},
'kafka': {
# 'level': 'DEBUG',
# 'class': 'logging.handlers.RotatingFileHandler',
# 'filename': '{}/kafka.log'.format(BASE_LOG_DIR),
# 'maxBytes': 1024*1024*5*20, # 5*20 MB
# 'maxBytes': 1024*5, # 5 KB
# 保留7天的日志,没份5M,5份大概是一个小时的日志内容,主要是kafka日志
# 'backupCount': int(5*1*24*7/20),
# 'formatter': 'standard',
'level': 'INFO',
'class': 'utils.graylog.graylog_django.GraylogHandler',
'app': 'erebus',
'file': 'kafka.log',
'host': GRAYLOG_HOST,
'port': GRAYLOG_PORT,
'localname': GRAYLOG_SOURCE,
},
'output_to_server': {
'level': 'WARNING', # 忽略debug/info信息
'class': 'logging.handlers.HTTPHandler',
'host': '127.0.0.1:8088',
'url': '/api/v1/log',
# 使用GET方法遇到url最大长度限制
'method': 'POST',
'formatter': 'verbose',
},
'jenkins': {
'level': 'DEBUG', # 忽略debug信息
'class': 'logging.handlers.RotatingFileHandler',
'filename': '{}/{}.log'.format(BASE_LOG_DIR, 'jenkins'),
'formatter': 'simple' if DEBUG else 'verbose',
'encoding': 'utf8',
'maxBytes': 1024*1024*5*20, # 5*20 MB
'backupCount': int(5*1*24*7/20),
},
'django': {
# 'level': 'INFO', # 忽略debug信息
# 'class': 'logging.handlers.RotatingFileHandler',
# 'filename': '{}/{}.log'.format(BASE_LOG_DIR, conf.get('log', 'name')),
# 'formatter': 'simple' if DEBUG else 'verbose',
# 'encoding': 'utf8',
# 'maxBytes': 1024*1024*5*20, # 5*20 MB
# 'backupCount': int(5*1*24*7/20),
'level': 'INFO', # 忽略debug信息
'class': 'utils.graylog.graylog_django.GraylogHandler',
'app': 'erebus',
'file': '{}.log'.format(conf.get('log', 'name')),
'host': GRAYLOG_HOST,
'port': GRAYLOG_PORT,
'localname': GRAYLOG_SOURCE,
},
'gunicorn_error': {
'level': 'INFO', # 忽略debug信息
'class': 'utils.graylog.graylog_django.GraylogHandler',
'app': 'erebus',
'file': 'gunicorn_error.log',
'host': GRAYLOG_HOST,
'port': GRAYLOG_PORT,
'localname': GRAYLOG_SOURCE,
},
'gunicorn_access': {
'level': 'INFO', # 忽略debug信息
'class': 'utils.graylog.graylog_django.GraylogHandler',
'app': 'erebus',
'file': 'gunicorn_error.log',
'host': GRAYLOG_HOST,
'port': GRAYLOG_PORT,
'localname': GRAYLOG_SOURCE,
},
'celery': {
'level': 'INFO', # 忽略debug信息
'class': 'utils.graylog.graylog_django.GraylogHandler',
'app': 'erebus',
'file': 'celery.log',
'host': GRAYLOG_HOST,
'port': GRAYLOG_PORT,
'localname': GRAYLOG_SOURCE,
},
'flower': {
'level': 'INFO', # 忽略debug信息
'class': 'utils.graylog.graylog_django.GraylogHandler',
'app': 'erebus',
'file': 'flower.log',
'host': GRAYLOG_HOST,
'port': GRAYLOG_PORT,
'localname': GRAYLOG_SOURCE,
},
'console': {
'level': 'DEBUG' if DEBUG else 'WARNING', # 所有的日志都会被输出到console
# 'filters': ['require_debug_true'],
'class': 'logging.StreamHandler',
'formatter': 'simple'
},
'operation': {
'level': 'INFO',
'class': 'logging.FileHandler',
'filename': '{}/{}.log'.format(BASE_LOG_DIR, 'operation'),
'formatter': 'operation',
'encoding': 'utf8'
},
'test': {
'level': 'INFO',
'class': 'logging.FileHandler',
'filename': '{}/{}.log'.format(BASE_LOG_DIR, 'test'),
'formatter': 'standard',
'encoding': 'utf8'
}
# 'mail_admins': {
# 'level': 'ERROR',
# 'class': 'django.utils.log.AdminEmailHandler',
# # 'filters': ['special']
# }
},
'loggers': {
# 可以通过使用空字符串:''来设置'catch all' logger
# 在以下设置中,将所有日志事件级别为WARNING及以上的日志发送给日志服务器,但配置为'propagate': False日志事件除外,
'': {
'handlers': ['default', 'output_to_server'],
# 'handlers': ['default'],
# 这样情况下的level设置是无效的,所有级别的信息都会传给handlers处理,由handlers的level界别决定
# 'level': 'ERROR',
'propagate': False
},
# 记录所有jenkins的requests相关的日志;jenkins->requests->urllib3
'urllib3': {
'handlers': ['jenkins'],
'level': 'DEBUG' if DEBUG else 'INFO',
'propagate': True
},
# 记录所有kakfa相关的日志kafka.conn/kafka.client/kafka.coordinator.consumer
'kafka': {
'handlers': ['kafka'],
'level': 'DEBUG' if DEBUG else 'INFO',
'propagate': True
},
# 这里必须使用名字django和django.request,目的是为了捕获django框架的日志内容
'django': {
'handlers': ['django', 'console'],
# 当 logger 处理一条消息时,会将自己的日志级别和这条消息的日志级别做对比。
# 如果消息的日志级别匹配或者高于 logger 的日志级别,它就会被进一步处理。
# 否则这条消息就会被忽略掉。当 logger 确定了一条消息需要处理之后,会把它传给 Handler。
# 把INFO及以上级别的日志传给handlers,然后由handlers根据handlers的level进一步处理日志输出
'level': 'DEBUG' if DEBUG else 'INFO',
'propagate': True, # 若值为False,表示日志不会传到上个层级,自然也不会传到default.log里
},
# 使用logger = logging.getLogger('django.request'), logger.info('info'),
# 可以把日志输出到'handlers': ['django', 'console'],
'django.request': {
# 即使和django的handlers一样,level也一样,也并不会产生2次相同的日志内容,应该是个并集。
'handlers': ['django', 'console'],
'level': 'DEBUG' if DEBUG else 'INFO',
# 会把日志向django.request的上层django传播
'propagate': True,
},
# sql语句
'django.db.backends': {
# 即使和django的handlers一样,level也一样,也并不会产生2次相同的日志内容,应该是个并集。
'handlers': ['django', 'console'],
'level': 'DEBUG' if DEBUG else 'INFO',
# 会把日志向django.request的上层django传播
'propagate': True,
},
# 'erebus.custom': {
# 'handlers': ['console', 'mail_admins'],
# 'level': 'INFO',
# # 'filters': ['special']
# },
# 名字随意起,用时,使用logger = logging.getLogger(conf.get('log', 'name'))获取,传到相应的loggers里就可以
'operation': {
'handlers': ['operation'],
'level': 'DEBUG' if DEBUG else 'INFO',
'propagate': True,
},
'test': {
'handlers': ['console', 'test'],
'level': 'DEBUG' if DEBUG else 'INFO',
'propagate': False, # 不要传给上一层级
},
'pipeline': {
'handlers': ['pipeline'],
'level': 'DEBUG' if DEBUG else 'INFO',
'propagate': False, # 不要传给上一层级
},
'gunicorn.error': {
'handlers': ['gunicorn_error'],
'level': 'DEBUG' if DEBUG else 'INFO',
'propagate': False, # 不要传给上一层级
},
'gunicorn.access': {
'handlers': ['gunicorn_access'],
'level': 'DEBUG' if DEBUG else 'INFO',
'propagate': False, # 不要传给上一层级
},
'celery': {
'handlers': ['celery'],
'level': 'DEBUG' if DEBUG else 'INFO',
'propagate': False, # 不要传给上一层级
},
'flower': {
'handlers': ['flower'],
'level': 'DEBUG' if DEBUG else 'INFO',
'propagate': False, # 不要传给上一层级
}
}
}
celery的log如何传递给django,由django管理的更多相关文章
- gunicorn的log如何传递给django,由django管理
gunicorn配置文件为gunicorn_config.py里面有日志的配置 # errorlog = '/home/admin/output/erebus/logs/gunicorn_error. ...
- django中将views.py中的python方法传递给html模板文件
常规的模板渲染 from django.db import models # Create your models here. class ArticalType(models.Model): cap ...
- JavaWeb -- 服务器传递给Servlet的对象 -- ServletConfig, ServletContext,Request, Response
1. ServletConfig 有一些东西不合适在程序中写死,应该写在web.xml中,比如 文字怎么显示, 访问数据库名 和 密码, servlet要读取的配置文件 等等.. l在Servle ...
- 如何获取url中的参数并传递给iframe中的报表
在使用报表软件时,用户系统左边一般有目录树,点击报表节点就会在右侧网页的iframe中显示出报表,同时点击的时候也会传递一些参数给网页,比如时间和用户信息等.如何使网页中的报表能够获取到传递过来的参数 ...
- AWK调用SHELL,并将变量传递给SHELL
在Shell脚本中调用awk是非常自然和简单的,以前还写过一个关于awk/shell相互传递变量的文章:awk与shell之间的变量传递方法在awk脚本中,如果需要调用shell脚本/命令,则需要使用 ...
- Jmeter----A接口response中body的某一个参数传递给B接口request的body中使用(参数的传递)
示例:将接口"获取待办列表"response中body的id值传递给接口"删除待办"request的body中使用: 操作步骤如下: 第一步:给"获取 ...
- 微软将把Windows Defender防火墙传递给 Linux 子系统
前不久,微软以 Azure Sphere OS 的形式发布了自己的 Linux 版本.而在最新的开发中,该公司又决定将其 Windows Defender 防火墙的传递给 Linux 子系统(WSL) ...
- 详解~实现Runnable方法创建线程之为什么要将Runnable接口的子类对象传递给Thread的构造函数
/** * @author zhao * @TIME 0419 22:56 End *定义线程的第二种方法:实现Runnable接口(不考虑安全问题) *步骤:1,定义一个子类实现Runnable接口 ...
- 通过BeanShell获取UUID并将参数传递给Jmeter
有些HTTPS请求报文的报文体中包含由客户端生成的UUID,在用Jmeter做接口自动化测试的时候,因为越过了客户端,直接向服务器端发送报文,所以,需要在Jmeter中通过beanshell获取UUI ...
随机推荐
- [ Educational Codeforces Round 65 (Rated for Div. 2)][二分]
https://codeforc.es/contest/1167/problem/E E. Range Deleting time limit per test 2 seconds memory li ...
- 发布一个在Web下输入密码时提示大写锁定键的Jquery插件
功能介绍:在Web下输入密码时提示大写锁定键,封装成jq插件方便有需要的同学!使用:$("#txtPWD").capsLockTip();截图预览:代码(2012-05-03 10 ...
- myeclipse2018大括号之前会自动加空格
- MySQL服务优化参数设置参考
l 通用类: key_buffer_size 含义:用于索引块的缓冲区大小,增加它可得到更好处理的索引(对所有读和多重写). 影响:对于MyISAM表的影响不是很大,MyISAM会使用系统的缓存来存储 ...
- 洛谷 P1309 瑞士轮 题解
每日一题 day4 打卡 Analysis 暴力+快排(其实是归并排序) 一开始天真的以为sort能过,结果光荣TLE,由于每次只更改相邻的元素,于是善于处理随机数的快排就会浪费很多时间.于是就想到归 ...
- luogu 1593
$Answer = A ^ B $ 的因子之和 将 $A$ 进行质因数分解$A = p_1 ^ {a_1} P_2 ^ {a_2} p_3 ^ {a_3} \cdots p_k ^ {a_k}$ $A ...
- ZROI Day6比赛总结
比赛还没结束而且我没有参加比赛就来这里了. T1 略 T2 设\(ans_d\)表示\(d|b_i\)的方案数(最后反演一下就可以) 设\(d\not|a_i\)的个数为\(l\)(可以\(O(n\l ...
- pyCharm专业版破解方案【附:四种破解】
前言: 一般适合我们的工具才是好的工具,通过调研对比发现pycharm还不错,其它工具就不一一列举了 pyCharm社区版可以永久免费,但是它不支持HTML, JS, and SQL等,为了方便以后使 ...
- Apache Flink - Window
Window: 在Streaming中,数据是无限且连续的,我们不可能等所有数据都到才进行处理,我们可以来一个就处理一下,但是有时我们需要做一些聚合类的处理,例如:在过去的1分钟内有多少用户点击了我们 ...
- pytest 基本用法
1.断言用assert,可以进行==,!=,+,-,*,/,<=,>=,is True.False,is not True.False ,in ,not in 等判断. import py ...