diff --git a/frontend-laminar/src/main/scala/ru/d10xa/jsonlogviewer/ViewElement.scala b/frontend-laminar/src/main/scala/ru/d10xa/jsonlogviewer/ViewElement.scala index 32ea829..7a53518 100644 --- a/frontend-laminar/src/main/scala/ru/d10xa/jsonlogviewer/ViewElement.scala +++ b/frontend-laminar/src/main/scala/ru/d10xa/jsonlogviewer/ViewElement.scala @@ -33,7 +33,9 @@ object ViewElement { commands = List.empty, inlineInput = Some(string), filter = config.filter, - formatIn = config.formatIn + formatIn = config.formatIn, + rawInclude = None, + rawExclude = None ) ) ) diff --git a/json-log-viewer/jvm/src/main/scala/ru/d10xa/jsonlogviewer/decline/yaml/ConfigYamlLoaderImpl.scala b/json-log-viewer/jvm/src/main/scala/ru/d10xa/jsonlogviewer/decline/yaml/ConfigYamlLoaderImpl.scala index ecc9895..d3b53c5 100644 --- a/json-log-viewer/jvm/src/main/scala/ru/d10xa/jsonlogviewer/decline/yaml/ConfigYamlLoaderImpl.scala +++ b/json-log-viewer/jvm/src/main/scala/ru/d10xa/jsonlogviewer/decline/yaml/ConfigYamlLoaderImpl.scala @@ -144,13 +144,18 @@ class ConfigYamlLoaderImpl extends ConfigYamlLoader { val formatInValidated : Validated[NonEmptyList[String], Option[FormatIn]] = parseOptionalFormatIn(feedFields, "formatIn") - + val rawIncludeValidated = + parseOptionalListString(feedFields, "rawInclude") + val rawExcludeValidated = + parseOptionalListString(feedFields, "rawExclude") ( nameValidated, commandsValidated, inlineInputValidated, filterValidated, - formatInValidated + formatInValidated, + rawIncludeValidated, + rawExcludeValidated ) .mapN(Feed.apply) } diff --git a/json-log-viewer/shared/src/main/scala/ru/d10xa/jsonlogviewer/LogViewerStream.scala b/json-log-viewer/shared/src/main/scala/ru/d10xa/jsonlogviewer/LogViewerStream.scala index 4181fc6..c19f2e4 100644 --- a/json-log-viewer/shared/src/main/scala/ru/d10xa/jsonlogviewer/LogViewerStream.scala +++ b/json-log-viewer/shared/src/main/scala/ru/d10xa/jsonlogviewer/LogViewerStream.scala @@ -3,16 +3,17 @@ package ru.d10xa.jsonlogviewer import cats.effect.IO import cats.effect.Ref import fs2.* -import ru.d10xa.jsonlogviewer.decline.Config -import ru.d10xa.jsonlogviewer.decline.Config.FormatIn import ru.d10xa.jsonlogviewer.decline.yaml.ConfigYaml import ru.d10xa.jsonlogviewer.decline.yaml.Feed +import ru.d10xa.jsonlogviewer.decline.Config +import ru.d10xa.jsonlogviewer.decline.Config.FormatIn import ru.d10xa.jsonlogviewer.formatout.ColorLineFormatter import ru.d10xa.jsonlogviewer.formatout.RawFormatter import ru.d10xa.jsonlogviewer.logfmt.LogfmtLogLineParser -import ru.d10xa.jsonlogviewer.query.QueryAST import ru.d10xa.jsonlogviewer.shell.ShellImpl +import scala.util.matching.Regex + object LogViewerStream { private val stdinLinesStream: Stream[IO, String] = @@ -21,7 +22,7 @@ object LogViewerStream { def stream( config: Config, configYamlRef: Ref[IO, Option[ConfigYaml]] - ): Stream[IO, String] = { + ): Stream[IO, String] = Stream.eval(configYamlRef.get).flatMap { configYamlOpt => val feedsOpt: Option[List[Feed]] = configYamlOpt.flatMap(_.feeds).filter(_.nonEmpty) @@ -47,14 +48,12 @@ object LogViewerStream { .intersperse("\n") .append(Stream.emit("\n")) } - } private def commandsAndInlineInputToStream( commands: List[String], inlineInput: Option[String] - ): Stream[IO, String] = { + ): Stream[IO, String] = new ShellImpl().mergeCommandsAndInlineInput(commands, inlineInput) - } def makeLogLineParser( config: Config, @@ -72,7 +71,7 @@ object LogViewerStream { lines: Stream[IO, String], configYamlRef: Ref[IO, Option[ConfigYaml]], index: Int - ): Stream[IO, String] = { + ): Stream[IO, String] = for { line <- lines optConfigYaml <- Stream.eval(configYamlRef.get) @@ -84,6 +83,12 @@ object LogViewerStream { .flatMap(_.feeds) .flatMap(_.lift(index).flatMap(_.filter)) .orElse(baseConfig.filter) + rawInclude = optConfigYaml + .flatMap(_.feeds) + .flatMap(_.lift(index).flatMap(_.rawInclude)) + rawExclude = optConfigYaml + .flatMap(_.feeds) + .flatMap(_.lift(index).flatMap(_.rawExclude)) feedName = optConfigYaml .flatMap(_.feeds) .flatMap(_.lift(index).flatMap(_.name)) @@ -99,9 +104,10 @@ object LogViewerStream { case Some(Config.FormatOut.Raw) => RawFormatter() case Some(Config.FormatOut.Pretty) | None => ColorLineFormatter(effectiveConfig, feedName) - evaluatedLine <- Stream - .emit(logLineParser.parse(line)) + .emit(line) + .filter(rawFilter(_, rawInclude, rawExclude)) + .map(logLineParser.parse) .filter(logLineFilter.grep) .filter(logLineFilter.logLineQueryPredicate) .through( @@ -116,6 +122,18 @@ object LogViewerStream { .map(_.toString) } yield evaluatedLine + def rawFilter( + str: String, + include: Option[List[String]], + exclude: Option[List[String]] + ): Boolean = { + val includeRegexes: List[Regex] = include.getOrElse(Nil).map(_.r) + val excludeRegexes: List[Regex] = exclude.getOrElse(Nil).map(_.r) + val includeMatches = includeRegexes.isEmpty || includeRegexes.exists( + _.findFirstIn(str).isDefined + ) + val excludeMatches = excludeRegexes.forall(_.findFirstIn(str).isEmpty) + includeMatches && excludeMatches } } diff --git a/json-log-viewer/shared/src/main/scala/ru/d10xa/jsonlogviewer/decline/yaml/Feed.scala b/json-log-viewer/shared/src/main/scala/ru/d10xa/jsonlogviewer/decline/yaml/Feed.scala index 292d1de..6a0d7f7 100644 --- a/json-log-viewer/shared/src/main/scala/ru/d10xa/jsonlogviewer/decline/yaml/Feed.scala +++ b/json-log-viewer/shared/src/main/scala/ru/d10xa/jsonlogviewer/decline/yaml/Feed.scala @@ -8,5 +8,7 @@ case class Feed( commands: List[String], inlineInput: Option[String], filter: Option[QueryAST], - formatIn: Option[FormatIn] + formatIn: Option[FormatIn], + rawInclude: Option[List[String]], + rawExclude: Option[List[String]] )