Chinaunix

标题: 关于切割日志的问题 [打印本页]

作者: vipty    时间: 2019-05-30 10:11
标题: 关于切割日志的问题
用sed切割日志是可以把两个时间段的日志全部切割出来,可是如果两个时间点有一个不对就切割不到
用awk也可以切割日志,也可以做到相对精确,可是里面有一些日志分了几行,没有时间点的行要不就全部跟出来,要是设置了数字就全部没有,这个怎么解决呀



作者: Shell_HAT    时间: 2019-05-30 13:15
把你的写的sed和awk发出来看看,在发一段样本日志方便测试。
作者: vipty    时间: 2019-05-30 13:48
回复 2# Shell_HAT

好的





作者: leowang119    时间: 2019-05-30 16:59
没有时间点的你不想要的话可以在执行awk时加入匹配模式,类似'/^\[/{if.......}'即可
作者: vipty    时间: 2019-05-30 17:09
回复 4# leowang119

就是在两个时间点内的全部都要所以才会有问题!

作者: vipty    时间: 2019-05-30 17:10
回复 2# Shell_HAT
[root@centos ~]# cat a
[2019-05-30 09:39:03.339] [DEBUG] [http-nio-8201-exec-2] [org.mybatis.spring.SqlSessionUtils] - Releasing transactional SqlSessio
[2019-05-30 09:39:03.339] [DEBUG] [http-nio-8201-exec-2] [org.mybatis.spring.SqlSessionUtils] - Transaction synchronization dereg
[2019-05-30 09:49:03.339] [DEBUG] [http-nio-8201-exec-2] [org.mybatis.spring.SqlSessionUtils] - Transaction synchronization closi
[2019-05-30 09:52:03.341] [DEBUG] [http-nio-8201-exec-2] [c.c.c.c.c.MasterSlaveRedisCacheServiceImpl] - redis del key=p2p_lock_Co
[2019-05-30 09:53:03.341] [ERROR] [http-nio-8201-exec-2] [c.c.core.aop.lock.TryLockAspect] - com.chuangjin.p2p.loan.exception.App
    at com.chuangjin.p2p.loan.service.FundRouter.packagingApplyFailMessage(FundRouter.java:321)
    at com.chuangjin.p2p.loan.service.FundRouter.route(FundRouter.java:206)
    at com.chuangjin.p2p.loan.service.FundRouter.routeAndUpdateContract(FundRouter.java:151)
    at com.chuangjin.p2p.loan.service.FundRouter$$FastClassBySpringCGLIB$$932cc0af.invoke(<generated>
    at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:721)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
    at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java
    at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:656)
    at com.chuangjin.p2p.loan.service.FundRouter$$EnhancerBySpringCGLIB$$f56059c3.routeAndUpdateContract(<generated>
    at com.chuangjin.p2p.loan.service.impl.ContractServiceImpl.apply(ContractServiceImpl.java:756)
    at com.chuangjin.p2p.loan.service.impl.ContractServiceImpl$$FastClassBySpringCGLIB$$32198976.invoke(<generated>
    at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:721)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
    at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:9
    at com.chuangjin.core.aop.lock.TryLockAspect.tryLockAround(TryLockAspect.java:4
[2019-05-30 09:54:03.905] [DEBUG] [http-nio-8201-exec-4] [org.mybatis.spring.SqlSessionUtils] - Creating a new SqlSession
[2019-05-30 09:55:03.905] [DEBUG] [http-nio-8201-exec-4] [org.mybatis.spring.SqlSessionUtils] - Registering transaction synchroni
[2019-05-30 09:56:03.905] [DEBUG] [http-nio-8201-exec-4] [o.m.s.t.SpringManagedTransaction] - JDBC Connection [com.alibaba.druid.
[2019-05-30 09:56:03.905] [DEBUG] [http-nio-8201-exec-4] [c.c.p.l.d.C.countBorrowSuccessContract] - ==>  Preparing: select count(
[2019-05-30 09:57:03.905] [DEBUG] [http-nio-8201-exec-4] [c.c.p.l.d.C.countBorrowSuccessContract] - ==> Parameters: 133012(Long)
[2019-05-30 09:58:03.906] [DEBUG] [http-nio-8201-exec-4] [c.c.p.l.d.C.countBorrowSuccessContract] - <==      Total: 1
[2019-05-30 09:59:03.906] [DEBUG] [http-nio-8201-exec-4] [org.mybatis.spring.SqlSessionUtils] - Releasing transactional SqlSessio


作者: vipty    时间: 2019-05-30 17:12
  1. [root@centos ~]# cat a
  2. [2019-05-30 09:39:03.339] [DEBUG] [http-nio-8201-exec-2] [org.mybatis.spring.SqlSessionUtils] - Releasing transactional SqlSessio
  3. [2019-05-30 09:39:03.339] [DEBUG] [http-nio-8201-exec-2] [org.mybatis.spring.SqlSessionUtils] - Transaction synchronization dereg
  4. [2019-05-30 09:49:03.339] [DEBUG] [http-nio-8201-exec-2] [org.mybatis.spring.SqlSessionUtils] - Transaction synchronization closi
  5. [2019-05-30 09:52:03.341] [DEBUG] [http-nio-8201-exec-2] [c.c.c.c.c.MasterSlaveRedisCacheServiceImpl] - redis del key=p2p_lock_Co
  6. [2019-05-30 09:53:03.341] [ERROR] [http-nio-8201-exec-2] [c.c.core.aop.lock.TryLockAspect] - com.chuangjin.p2p.loan.exception.App
  7.         at com.chuangjin.p2p.loan.service.FundRouter.packagingApplyFailMessage(FundRouter.java:321)
  8.         at com.chuangjin.p2p.loan.service.FundRouter.route(FundRouter.java:206)
  9.         at com.chuangjin.p2p.loan.service.FundRouter.routeAndUpdateContract(FundRouter.java:151)
  10.         at com.chuangjin.p2p.loan.service.FundRouter$FastClassBySpringCGLIB$932cc0af.invoke(<generated>)
  11.         at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
  12.         at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:721)
  13.         at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
  14.         at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java
  15.         at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.
  16.         at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
  17.         at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
  18.         at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:656)
  19.         at com.chuangjin.p2p.loan.service.FundRouter$EnhancerBySpringCGLIB$f56059c3.routeAndUpdateContract(<generated>)
  20.         at com.chuangjin.p2p.loan.service.impl.ContractServiceImpl.apply(ContractServiceImpl.java:756)
  21.         at com.chuangjin.p2p.loan.service.impl.ContractServiceImpl$FastClassBySpringCGLIB$32198976.invoke(<generated>)
  22.         at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
  23.         at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:721)
  24.         at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
  25.         at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:9
  26.         at com.chuangjin.core.aop.lock.TryLockAspect.tryLockAround(TryLockAspect.java:48)
  27. [2019-05-30 09:54:03.905] [DEBUG] [http-nio-8201-exec-4] [org.mybatis.spring.SqlSessionUtils] - Creating a new SqlSession
  28. [2019-05-30 09:55:03.905] [DEBUG] [http-nio-8201-exec-4] [org.mybatis.spring.SqlSessionUtils] - Registering transaction synchroni
  29. [2019-05-30 09:56:03.905] [DEBUG] [http-nio-8201-exec-4] [o.m.s.t.SpringManagedTransaction] - JDBC Connection [com.alibaba.druid.
  30. [2019-05-30 09:56:03.905] [DEBUG] [http-nio-8201-exec-4] [c.c.p.l.d.C.countBorrowSuccessContract] - ==>  Preparing: select count(
  31. [2019-05-30 09:57:03.905] [DEBUG] [http-nio-8201-exec-4] [c.c.p.l.d.C.countBorrowSuccessContract] - ==> Parameters: 133012(Long)
  32. [2019-05-30 09:58:03.906] [DEBUG] [http-nio-8201-exec-4] [c.c.p.l.d.C.countBorrowSuccessContract] - <==      Total: 1
  33. [2019-05-30 09:59:03.906] [DEBUG] [http-nio-8201-exec-4] [org.mybatis.spring.SqlSessionUtils] - Releasing transactional SqlSessio
复制代码



作者: jzsjm1002    时间: 2019-05-30 17:38
本帖最后由 jzsjm1002 于 2019-05-30 17:50 编辑

回复 7# vipty

楼主需求是这样吗?

123.png (59.02 KB, 下载次数: 115)

123.png

作者: vipty    时间: 2019-05-30 20:08
回复 8# jzsjm1002

是的,可是sed切割日志一定要有第一个时间点,如果第一个时间点不能精确确定就没办法切割!

作者: jzsjm1002    时间: 2019-05-30 21:41
回复 9# vipty

不能精确就用正则去匹配 通过分秒 来定位

123.png (69.89 KB, 下载次数: 110)

123.png

作者: vipty    时间: 2019-05-31 10:02
回复 10# jzsjm1002

正则也用过,可是如果十分钟内没有日志输出呢?这个毕竟不太精确。

作者: jzsjm1002    时间: 2019-05-31 10:10
回复 11# vipty

可以通过写脚本来判断 具体看楼主需要截取什么了也可以通过ELK来实现日志页面浏览 日志分析 具体看楼主需求


作者: vipty    时间: 2019-05-31 10:23
回复 12# jzsjm1002

嗯,如果用awk,sed没办法切割的话只能考虑使用elk了。





欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2