@@ -3,16 +3,17 @@ package ru.d10xa.jsonlogviewer
33import cats .effect .IO
44import cats .effect .Ref
55import fs2 .*
6- import ru .d10xa .jsonlogviewer .decline .Config
7- import ru .d10xa .jsonlogviewer .decline .Config .FormatIn
86import ru .d10xa .jsonlogviewer .decline .yaml .ConfigYaml
97import ru .d10xa .jsonlogviewer .decline .yaml .Feed
8+ import ru .d10xa .jsonlogviewer .decline .Config
9+ import ru .d10xa .jsonlogviewer .decline .Config .FormatIn
1010import ru .d10xa .jsonlogviewer .formatout .ColorLineFormatter
1111import ru .d10xa .jsonlogviewer .formatout .RawFormatter
1212import ru .d10xa .jsonlogviewer .logfmt .LogfmtLogLineParser
13- import ru .d10xa .jsonlogviewer .query .QueryAST
1413import ru .d10xa .jsonlogviewer .shell .ShellImpl
1514
15+ import scala .util .matching .Regex
16+
1617object LogViewerStream {
1718
1819 private val stdinLinesStream : Stream [IO , String ] =
@@ -21,7 +22,7 @@ object LogViewerStream {
2122 def stream (
2223 config : Config ,
2324 configYamlRef : Ref [IO , Option [ConfigYaml ]]
24- ): Stream [IO , String ] = {
25+ ): Stream [IO , String ] =
2526 Stream .eval(configYamlRef.get).flatMap { configYamlOpt =>
2627 val feedsOpt : Option [List [Feed ]] =
2728 configYamlOpt.flatMap(_.feeds).filter(_.nonEmpty)
@@ -47,14 +48,12 @@ object LogViewerStream {
4748 .intersperse(" \n " )
4849 .append(Stream .emit(" \n " ))
4950 }
50- }
5151
5252 private def commandsAndInlineInputToStream (
5353 commands : List [String ],
5454 inlineInput : Option [String ]
55- ): Stream [IO , String ] = {
55+ ): Stream [IO , String ] =
5656 new ShellImpl ().mergeCommandsAndInlineInput(commands, inlineInput)
57- }
5857
5958 def makeLogLineParser (
6059 config : Config ,
@@ -72,7 +71,7 @@ object LogViewerStream {
7271 lines : Stream [IO , String ],
7372 configYamlRef : Ref [IO , Option [ConfigYaml ]],
7473 index : Int
75- ): Stream [IO , String ] = {
74+ ): Stream [IO , String ] =
7675 for {
7776 line <- lines
7877 optConfigYaml <- Stream .eval(configYamlRef.get)
@@ -84,6 +83,12 @@ object LogViewerStream {
8483 .flatMap(_.feeds)
8584 .flatMap(_.lift(index).flatMap(_.filter))
8685 .orElse(baseConfig.filter)
86+ rawInclude = optConfigYaml
87+ .flatMap(_.feeds)
88+ .flatMap(_.lift(index).flatMap(_.rawInclude))
89+ rawExclude = optConfigYaml
90+ .flatMap(_.feeds)
91+ .flatMap(_.lift(index).flatMap(_.rawExclude))
8792 feedName = optConfigYaml
8893 .flatMap(_.feeds)
8994 .flatMap(_.lift(index).flatMap(_.name))
@@ -99,9 +104,10 @@ object LogViewerStream {
99104 case Some (Config .FormatOut .Raw ) => RawFormatter ()
100105 case Some (Config .FormatOut .Pretty ) | None =>
101106 ColorLineFormatter (effectiveConfig, feedName)
102-
103107 evaluatedLine <- Stream
104- .emit(logLineParser.parse(line))
108+ .emit(line)
109+ .filter(rawFilter(_, rawInclude, rawExclude))
110+ .map(logLineParser.parse)
105111 .filter(logLineFilter.grep)
106112 .filter(logLineFilter.logLineQueryPredicate)
107113 .through(
@@ -116,6 +122,18 @@ object LogViewerStream {
116122 .map(_.toString)
117123 } yield evaluatedLine
118124
125+ def rawFilter (
126+ str : String ,
127+ include : Option [List [String ]],
128+ exclude : Option [List [String ]]
129+ ): Boolean = {
130+ val includeRegexes : List [Regex ] = include.getOrElse(Nil ).map(_.r)
131+ val excludeRegexes : List [Regex ] = exclude.getOrElse(Nil ).map(_.r)
132+ val includeMatches = includeRegexes.isEmpty || includeRegexes.exists(
133+ _.findFirstIn(str).isDefined
134+ )
135+ val excludeMatches = excludeRegexes.forall(_.findFirstIn(str).isEmpty)
136+ includeMatches && excludeMatches
119137 }
120138
121139}
0 commit comments