- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想搜索长 .json loggly 文件中的特定字符串,包括其行号,并且还想打印搜索行上方和下方的 5 行。你能帮我吗?
它总是返回“NOT FOUND”。之后,现在我只能通过下面显示的程序获得一些输出。将 open('logg.json', 'r') 作为 f: 对于 ln,enumerate(f) 中的行: 如果“错误崩溃日志”在行: 我=ln-25 对于 (ln-25,ln+25) 中的 i: l = linecache.getline('logg.json', i) 我+=1 打印(ln,l) print("下一个错误")
最佳答案
file.readlines()
返回行列表。 Lines 确实包含换行符 (\n
)。
您需要指定换行符来匹配行:
ln = data.index("error CRASHLOG\n")
如果你想找到包含目标字符串的行,你需要迭代这些行:
with open('logg.json', 'r') as f:
for ln, line in enumerate(f):
if "error CRASHLOG" in line:
# You now know the line index (`ln`)
# Print above/below 5 lines here.
break
else:
print("Not Found")
顺便说一句,这种工作可以使用 grep(1)
轻松完成:
grep -C 5 'error CRASHLOG' logg.json || echo 'Not Found'
更新
以下是更完整的代码:
from collections import deque
from itertools import islice, chain
import sys
with open('logg.json', 'r') as f:
last_lines = deque(maxlen=5) # contains the last (up to) 5 lines.
for ln, line in enumerate(f):
if "error CRASHLOG" in line:
sys.stdout.writelines(chain(last_lines, [line], islice(f, 5)))
last_lines.append(line)
else:
print("Not Found")
关于.json Loggly 文件的 Python 编程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22166414/
有人可以帮助我吗? 有没有办法通过nodejs上的winston-loggly发送致命级别消息? 有没有办法发送 500 状态代码而不是“info”字符串? const winston = requ
已结束。此问题正在寻求书籍、工具、软件库等的推荐。它不满足Stack Overflow guidelines 。目前不接受答案。 我们不允许提出寻求书籍、工具、软件库等推荐的问题。您可以编辑问题,以便
Loggly 每秒可以处理多少来自客户端的请求?我每秒只能处理大约 10-20 个请求,我想知道这是否正常。 最佳答案 我刚刚运行了一系列测试,发现它无法通过使用 syslog-ng 的 tcp 连接
在过去的几个月里,我们一直错误地登录到 Loggly。历史上,我们的上下文是字符串的数字数组。 ['message1', 'message2, 'message3' ...] 我们希望向 loggly
我想将 Monolog 日志从我的 Laravel 5.1 应用程序发送到 Loggly.com 在线日志管理服务。来自所有可能的环境,包括本地开发。 最佳答案 我发现了一些过时的库和复杂的方法来做到
我为 Winston 设置了 3 种传输:控制台、文件和 Loggly(使用 https://github.com/loggly/winston-loggly-bulk )。 虽然控制台和文件可以正确
我想搜索长 .json loggly 文件中的特定字符串,包括其行号,并且还想打印搜索行上方和下方的 5 行。你能帮我吗? 它总是返回“NOT FOUND”。之后,现在我只能通过下面显示的程序获得一些
我正在将 Loggly 日志记录框架集成到我的 AngularJS 客户端应用程序中,尽管我使用 JavaScript 缩小和混淆,但 Loggly token 仍然可以在源代码中轻松发现: e.in
"> 我在 web.config 中使用此代码将日志发送到 loggly。无法将日志发送到 loggly。请帮助发送日志。" -
我有一个 golang 项目,我正在尝试使用 loggly 日志记录,正如他们在 https://www.loggly.com/blog/logging-to-loggly-from-go-with-
我想在我的新 PaaS python 应用程序中尝试 Loggly,因为我通常针对 Linux 服务器进行编码,并且只使用标准旋转文件处理程序。这提出了一个问题,因为他们记录的配置仅涵盖使用 .con
我想在 Loggly 中使用 Serilog 消息模板。 我已将带有 Serilog 的 Loggly 配置到我的应用程序中。 var logglySettings = new LogglySetti
我正在按照 here 概述的步骤在我的 nodejs 应用程序中配置 loggly: npm install winston npm install winston-loggly-bulk 在 ind
我正在将 loggly 与 Node js 一起使用。这是初始化脚本: var winston = require('winston'); require('winston-loggly-bulk'
我知道他们把它们存储在某个地方。也许是 DynamoDB 或 S3 存储桶? 我想使用 Cloudwatch 作为我的 EC2 实例的日志存档,并对其进行设置,以便将它们传递到 Loggly 进行查看
我在公司使用 Loggly 来跟踪 nginx 日志。 我最近切换到 Amazon ECS,但我在为其配置 loggly 时遇到了困难。 在amazon ECS界面,我配置loggly如下: 但是根据
我正在构建一个 erlang 应用程序并利用 lager — 由 Basho Technologies 编写的日志框架。 我想将日志输出发送到 Papertrail,或者失败 Loggly。 任何人都
有没有办法使用log4j将java(jboss as)应用程序连接到openshift上的loggly? 您可以完全控制服务器的 log4j 配置在此处配置:https://www.loggly.co
实际上我正在使用 log4j 1.2 和 xml 配置文件;是否可以将各个类的日志重定向到指定文件中;我想登录3个文件。 -->
我有一个物联网项目在使用 Raspbian Jessie 操作系统的 Raspberry Pi 2 上运行。 这是一个在 NodeJS (v4) 中运行的网络服务器,我使用 Winston 登录到 L
我是一名优秀的程序员,十分优秀!