我使用Fluentd配置和regexp解析器来解析日志。
这是我在fluentd的原始日志:
2022-09-22 18:15:09,633 [springHikariCP housekeeper ] DEBUG HikariPool - springHikariCP - Fill pool skipped, pool is at sufficient level.
2022-09-22 18:15:14,968 [ringHikariCP connection closer] DEBUG PoolBase - springHikariCP - Closing connection com.mysql.cj.jdbc.ConnectionImpl@7f535ea4: (connection has passed maxLifetime)
我想使用regexp为上述日志创建json格式,如下所示:
{
"logtime": "2022-09-22 18:15:09,633",
"Logger Name": "[springHikariCP housekeeper ]",
"Log level": "DEBUG",
"message": "HikariPool - springHikariCP - Fill pool skipped, pool is at sufficient level"
}
{
"logtime": "2022-09-22 18:15:09,633",
"Logger Name": "[ringHikariCP connection closer]",
"Log level": "DEBUG",
"message": "PoolBase - springHikariCP - Closing connectioncom.mysql.cj.jdbc.ConnectionImpl@7f535ea4: (connection has passed maxLifetime)"
}
有Ruby经验的人可以帮助我为上面的日志创建Ruby正则表达式吗
1条答案
按热度按时间ryevplcw1#
正则表达式应该简单明了,例如:
Online Test
然后,使用替换(
gsub
,请参见下面的示例)或将这些部分组合成一个新字符串(match
)来重新组合这些部分: