Skip to content

Commit 627d5fb

Browse files
committed
Add rawExclude, rawInclude to Feed
1 parent abda751 commit 627d5fb

File tree

4 files changed

+41
-14
lines changed

4 files changed

+41
-14
lines changed

frontend-laminar/src/main/scala/ru/d10xa/jsonlogviewer/ViewElement.scala

+3-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ object ViewElement {
3333
commands = List.empty,
3434
inlineInput = Some(string),
3535
filter = config.filter,
36-
formatIn = config.formatIn
36+
formatIn = config.formatIn,
37+
rawInclude = None,
38+
rawExclude = None
3739
)
3840
)
3941
)

json-log-viewer/jvm/src/main/scala/ru/d10xa/jsonlogviewer/decline/yaml/ConfigYamlLoaderImpl.scala

+7-2
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,18 @@ class ConfigYamlLoaderImpl extends ConfigYamlLoader {
144144
val formatInValidated
145145
: Validated[NonEmptyList[String], Option[FormatIn]] =
146146
parseOptionalFormatIn(feedFields, "formatIn")
147-
147+
val rawIncludeValidated =
148+
parseOptionalListString(feedFields, "rawInclude")
149+
val rawExcludeValidated =
150+
parseOptionalListString(feedFields, "rawExclude")
148151
(
149152
nameValidated,
150153
commandsValidated,
151154
inlineInputValidated,
152155
filterValidated,
153-
formatInValidated
156+
formatInValidated,
157+
rawIncludeValidated,
158+
rawExcludeValidated
154159
)
155160
.mapN(Feed.apply)
156161
}

json-log-viewer/shared/src/main/scala/ru/d10xa/jsonlogviewer/LogViewerStream.scala

+28-10
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,17 @@ package ru.d10xa.jsonlogviewer
33
import cats.effect.IO
44
import cats.effect.Ref
55
import fs2.*
6-
import ru.d10xa.jsonlogviewer.decline.Config
7-
import ru.d10xa.jsonlogviewer.decline.Config.FormatIn
86
import ru.d10xa.jsonlogviewer.decline.yaml.ConfigYaml
97
import ru.d10xa.jsonlogviewer.decline.yaml.Feed
8+
import ru.d10xa.jsonlogviewer.decline.Config
9+
import ru.d10xa.jsonlogviewer.decline.Config.FormatIn
1010
import ru.d10xa.jsonlogviewer.formatout.ColorLineFormatter
1111
import ru.d10xa.jsonlogviewer.formatout.RawFormatter
1212
import ru.d10xa.jsonlogviewer.logfmt.LogfmtLogLineParser
13-
import ru.d10xa.jsonlogviewer.query.QueryAST
1413
import ru.d10xa.jsonlogviewer.shell.ShellImpl
1514

15+
import scala.util.matching.Regex
16+
1617
object 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
}

json-log-viewer/shared/src/main/scala/ru/d10xa/jsonlogviewer/decline/yaml/Feed.scala

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,7 @@ case class Feed(
88
commands: List[String],
99
inlineInput: Option[String],
1010
filter: Option[QueryAST],
11-
formatIn: Option[FormatIn]
11+
formatIn: Option[FormatIn],
12+
rawInclude: Option[List[String]],
13+
rawExclude: Option[List[String]]
1214
)

0 commit comments

Comments
 (0)