@@ -3,16 +3,17 @@ package ru.d10xa.jsonlogviewer
3
3
import cats .effect .IO
4
4
import cats .effect .Ref
5
5
import fs2 .*
6
- import ru .d10xa .jsonlogviewer .decline .Config
7
- import ru .d10xa .jsonlogviewer .decline .Config .FormatIn
8
6
import ru .d10xa .jsonlogviewer .decline .yaml .ConfigYaml
9
7
import ru .d10xa .jsonlogviewer .decline .yaml .Feed
8
+ import ru .d10xa .jsonlogviewer .decline .Config
9
+ import ru .d10xa .jsonlogviewer .decline .Config .FormatIn
10
10
import ru .d10xa .jsonlogviewer .formatout .ColorLineFormatter
11
11
import ru .d10xa .jsonlogviewer .formatout .RawFormatter
12
12
import ru .d10xa .jsonlogviewer .logfmt .LogfmtLogLineParser
13
- import ru .d10xa .jsonlogviewer .query .QueryAST
14
13
import ru .d10xa .jsonlogviewer .shell .ShellImpl
15
14
15
+ import scala .util .matching .Regex
16
+
16
17
object LogViewerStream {
17
18
18
19
private val stdinLinesStream : Stream [IO , String ] =
@@ -21,7 +22,7 @@ object LogViewerStream {
21
22
def stream (
22
23
config : Config ,
23
24
configYamlRef : Ref [IO , Option [ConfigYaml ]]
24
- ): Stream [IO , String ] = {
25
+ ): Stream [IO , String ] =
25
26
Stream .eval(configYamlRef.get).flatMap { configYamlOpt =>
26
27
val feedsOpt : Option [List [Feed ]] =
27
28
configYamlOpt.flatMap(_.feeds).filter(_.nonEmpty)
@@ -47,14 +48,12 @@ object LogViewerStream {
47
48
.intersperse(" \n " )
48
49
.append(Stream .emit(" \n " ))
49
50
}
50
- }
51
51
52
52
private def commandsAndInlineInputToStream (
53
53
commands : List [String ],
54
54
inlineInput : Option [String ]
55
- ): Stream [IO , String ] = {
55
+ ): Stream [IO , String ] =
56
56
new ShellImpl ().mergeCommandsAndInlineInput(commands, inlineInput)
57
- }
58
57
59
58
def makeLogLineParser (
60
59
config : Config ,
@@ -72,7 +71,7 @@ object LogViewerStream {
72
71
lines : Stream [IO , String ],
73
72
configYamlRef : Ref [IO , Option [ConfigYaml ]],
74
73
index : Int
75
- ): Stream [IO , String ] = {
74
+ ): Stream [IO , String ] =
76
75
for {
77
76
line <- lines
78
77
optConfigYaml <- Stream .eval(configYamlRef.get)
@@ -84,6 +83,12 @@ object LogViewerStream {
84
83
.flatMap(_.feeds)
85
84
.flatMap(_.lift(index).flatMap(_.filter))
86
85
.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))
87
92
feedName = optConfigYaml
88
93
.flatMap(_.feeds)
89
94
.flatMap(_.lift(index).flatMap(_.name))
@@ -99,9 +104,10 @@ object LogViewerStream {
99
104
case Some (Config .FormatOut .Raw ) => RawFormatter ()
100
105
case Some (Config .FormatOut .Pretty ) | None =>
101
106
ColorLineFormatter (effectiveConfig, feedName)
102
-
103
107
evaluatedLine <- Stream
104
- .emit(logLineParser.parse(line))
108
+ .emit(line)
109
+ .filter(rawFilter(_, rawInclude, rawExclude))
110
+ .map(logLineParser.parse)
105
111
.filter(logLineFilter.grep)
106
112
.filter(logLineFilter.logLineQueryPredicate)
107
113
.through(
@@ -116,6 +122,18 @@ object LogViewerStream {
116
122
.map(_.toString)
117
123
} yield evaluatedLine
118
124
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
119
137
}
120
138
121
139
}
0 commit comments