-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR does the following: * aligns JSON logs across the two backends * removes implifyjson logs in favour of contextual JSON logging * adds a custom syntax for `--log-context` also removing `--no-log-context` (see the docs/logging.md change for details) * switches the ceil analysis to contextual logs --------- Co-authored-by: github-actions <[email protected]>
- Loading branch information
1 parent
31bf501
commit 6e57788
Showing
30 changed files
with
629 additions
and
34,131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
module Booster.Log.Context (ContextFilter, mustMatch, readContextFilter, readMatch) where | ||
|
||
import Control.Applicative ((<|>)) | ||
import Data.Attoparsec.ByteString.Char8 qualified as A | ||
import Data.ByteString.Char8 qualified as BS | ||
import Data.Char (isSpace) | ||
import Data.List.Extra (replace) | ||
|
||
data ContextFilterSingle | ||
= Exact BS.ByteString | ||
| Prefix BS.ByteString | ||
| Suffix BS.ByteString | ||
| Infix BS.ByteString | ||
| Negate ContextFilterSingle | ||
deriving (Show) | ||
|
||
data ContextFilter | ||
= First [ContextFilterSingle] | ||
| ThenDirectChild [ContextFilterSingle] ContextFilter | ||
| ThenChild [ContextFilterSingle] ContextFilter | ||
| Last [ContextFilterSingle] | ||
deriving (Show) | ||
|
||
reserved :: String | ||
reserved = "|*!>,." | ||
|
||
stringP :: A.Parser BS.ByteString | ||
stringP = A.takeWhile1 (not . (`elem` reserved)) | ||
|
||
singleP :: A.Parser ContextFilterSingle | ||
singleP = | ||
A.char '!' *> A.skipSpace *> (Negate <$> singleP) | ||
<|> A.char '*' *> (Infix <$> stringP) <* A.char '*' | ||
-- we want to allow * being parsed as `Suffix ""` so we allow the empty string via `takeWhile` | ||
<|> A.char '*' *> (Suffix . BS.dropWhileEnd isSpace <$> A.takeWhile (not . (`elem` reserved))) | ||
<|> Prefix . BS.dropWhile isSpace <$> stringP <* A.char '*' | ||
<|> Exact . BS.strip <$> stringP | ||
|
||
orP :: A.Parser [ContextFilterSingle] | ||
orP = singleP `A.sepBy` (A.char '|') | ||
|
||
contextFilterP :: A.Parser ContextFilter | ||
contextFilterP = | ||
A.skipSpace | ||
*> ( ThenChild <$> (orP <* A.skipSpace <* A.char '>') <*> contextFilterP | ||
<|> ThenDirectChild <$> (orP <* A.skipSpace <* A.char ',') <*> contextFilterP | ||
<|> Last <$> (orP <* A.skipSpace <* A.char '.') | ||
<|> First <$> orP | ||
) | ||
|
||
readContextFilter :: String -> Either String ContextFilter | ||
readContextFilter = | ||
A.parseOnly (contextFilterP <* A.skipSpace <* A.endOfInput) . BS.pack . replace "\"" "" | ||
|
||
matchSingle :: ContextFilterSingle -> BS.ByteString -> Bool | ||
matchSingle (Exact c) s = c == s | ||
matchSingle (Prefix c) s = BS.isPrefixOf c s | ||
matchSingle (Suffix c) s = BS.isSuffixOf c s | ||
matchSingle (Infix c) s = BS.isInfixOf c s | ||
matchSingle (Negate c) s = not $ matchSingle c s | ||
|
||
mustMatch :: ContextFilter -> [BS.ByteString] -> Bool | ||
mustMatch (First cs) [] = any (flip matchSingle "") cs | ||
mustMatch (First cs) (x : _) = any (flip matchSingle x) cs | ||
mustMatch (Last cs) [x] = any (flip matchSingle x) cs | ||
mustMatch Last{} _ = False | ||
mustMatch (_ `ThenDirectChild` _) [] = False | ||
mustMatch (cs `ThenDirectChild` css) (x : xs) = | ||
any (flip matchSingle x) cs && mustMatch css xs | ||
mustMatch (_ `ThenChild` _) [] = False | ||
mustMatch (cs `ThenChild` css) (x : xs) = | ||
any (flip matchSingle x) cs && mayMatch css xs | ||
|
||
mayMatch :: ContextFilter -> [BS.ByteString] -> Bool | ||
mayMatch c [] = mustMatch c [] | ||
mayMatch c (x : xs) = mustMatch c (x : xs) || mayMatch c xs | ||
|
||
readMatch :: BS.ByteString -> [BS.ByteString] -> Either String Bool | ||
readMatch pat' xs = do | ||
pat <- A.parseOnly (contextFilterP <* A.skipSpace <* A.endOfInput) pat' | ||
pure $ mustMatch pat xs |
Oops, something went wrong.