Skip to content

One-line contextual logging of Kore actions #3837

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 49 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
e586d72
Work on one-line contexts for Kore
geo2a Apr 24, 2024
9d34b52
Add term hashes to logs, layout terms in one line
geo2a Apr 25, 2024
7890d30
Add DebugContext log entry
geo2a Apr 25, 2024
1cf6537
Add RPC method contexts
geo2a Apr 25, 2024
97a0da7
Add rule ids to rewrite rule log entries
geo2a Apr 25, 2024
e35ae82
Make rewrite logging contextual
geo2a Apr 25, 2024
211b321
Render DebugAppliedRewriteRule
geo2a Apr 25, 2024
cc04ac9
Improve DebugAttemptedRewriteRules code
geo2a Apr 25, 2024
e4c820a
Switch standard/oneline pretty render at the top level
geo2a Apr 25, 2024
adeec1f
Do not reverse the context in oneline log
geo2a Apr 25, 2024
a4bb8ad
Add oneLineContextDoc to DebugAttemptsUnification
geo2a Apr 25, 2024
5feb2bb
Fix kore-rpc-dev
geo2a Apr 25, 2024
b068f0f
Put rewrite success msg in brackets
geo2a Apr 25, 2024
b86d960
Only shorten failure if it is long
geo2a Apr 26, 2024
4ac7f8b
Merge remote-tracking branch 'origin/master' into georgy/kore-context…
geo2a Apr 29, 2024
d048a2a
Merge remote-tracking branch 'origin/master' into georgy/kore-context…
geo2a Apr 30, 2024
e718551
Rename log type used by Booster
geo2a Apr 26, 2024
da59a3b
Factor-out renderStandardPretty
geo2a Apr 26, 2024
c9d7d41
Refactor LogBooster to allow an arbitrary number of log actions
geo2a Apr 26, 2024
6988bfd
Work on Kore-Booster logging interop
geo2a Apr 26, 2024
da57cdb
Separate Kore logging stuff needed for Booster
geo2a Apr 26, 2024
bef669b
Move log actions definition up to Server.hs
geo2a Apr 29, 2024
dc4cb34
Rename LogBooster to LogProxy
geo2a Apr 29, 2024
8d7e36f
Enable file logging in kore-rpc-dev
geo2a Apr 29, 2024
00fa22d
Fix import
geo2a Apr 29, 2024
fbfb36e
Remove unused pragma
geo2a Apr 29, 2024
c570e45
Use more precise typing in log entry selector
geo2a Apr 29, 2024
ba4747b
Translate log levels to Kore log entries correctly
geo2a Apr 29, 2024
09e5d65
Refactor LogProxy again, add late filter predicate
geo2a Apr 29, 2024
785eac9
Fix stuff post-rebase
geo2a Apr 30, 2024
6dfde22
Format with fourmolu
invalid-email-address Apr 30, 2024
78c9d63
Adapt servers to the new logging
geo2a Apr 30, 2024
000c002
Add log format CLI argument
geo2a Apr 30, 2024
ebcdc64
Merge remote-tracking branch 'origin/master' into georgy/better-kore-…
geo2a May 2, 2024
c36a1b3
Don't shorten rule id in json logs
geo2a May 2, 2024
1adbaa1
Remove '...truncated' from short failure descriptions
geo2a May 2, 2024
0fba951
Add start-up messaged (no way around them currently)
geo2a May 2, 2024
eb82076
hlint
geo2a May 2, 2024
1658c36
remove dead code
geo2a May 2, 2024
4dc2cac
Fix unit tests
geo2a May 2, 2024
6c4c8cc
Format with fourmolu
invalid-email-address May 2, 2024
b571a00
Fix json log file test
geo2a May 2, 2024
0144916
De-duplicate showHashHex
geo2a May 6, 2024
f6b6b1d
Only apply globs to the context part of Kore log messages
geo2a May 6, 2024
bce8a4f
Filter-out brackets from contexts to make glob matches consistent
geo2a May 6, 2024
133dfc2
Format with fourmolu
invalid-email-address May 6, 2024
19fa796
Update kore-rpc-types/src/Kore/Util.hs
geo2a May 7, 2024
13f789a
Format with fourmolu
invalid-email-address May 7, 2024
536250e
Merge branch 'master' into georgy/better-kore-logging
rv-jenkins May 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions booster/library/Booster/CLOptions.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
module Booster.CLOptions (
CLOptions (..),
EquationOptions (..),
LogFormat (..),
clOptionsParser,
adjustLogLevels,
versionInfoParser,
Expand Down Expand Up @@ -31,6 +32,7 @@ data CLOptions = CLOptions
, port :: Int
, logLevels :: [LogLevel]
, logTimeStamps :: Bool
, logFormat :: LogFormat
, logContexts :: [String]
, notLogContexts :: [String]
, simplificationLogFile :: Maybe FilePath
Expand All @@ -41,6 +43,18 @@ data CLOptions = CLOptions
}
deriving (Show)

data LogFormat
= Standard
| OneLine
| Json
deriving (Eq)

instance Show LogFormat where
show = \case
OneLine -> "oneline"
Standard -> "standard"
Json -> "json"

clOptionsParser :: Parser CLOptions
clOptionsParser =
CLOptions
Expand Down Expand Up @@ -82,6 +96,14 @@ clOptionsParser =
)
)
<*> switch (long "log-timestamps" <> help "Add timestamps to logs")
<*> option
(eitherReader readLogFormat)
( metavar "LOGFORMAT"
<> value OneLine
<> long "log-format"
<> help "Format to output logs in"
<> showDefault
)
<*> many
( option
str
Expand Down Expand Up @@ -143,6 +165,13 @@ clOptionsParser =
. toPascal
. fromKebab

readLogFormat :: String -> Either String LogFormat
readLogFormat = \case
"oneline" -> Right OneLine
"standard" -> Right Standard
"json" -> Right Json
other -> Left $ other <> ": Unsupported log format"

-- custom log levels that can be selected
allowedLogLevels :: [(String, String)]
allowedLogLevels =
Expand Down
7 changes: 1 addition & 6 deletions booster/library/Booster/Log.hs
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,10 @@ import Data.List.Extra (splitOn, takeEnd)
import Data.Set qualified as Set
import Data.String (IsString)
import Data.Text (Text, pack)
import Data.Text qualified as Text
import Data.Text.Lazy qualified as LazyText
import Data.Word (Word64)
import GHC.Exts (IsString (..))
import GHC.TypeLits (KnownSymbol, symbolVal)
import Numeric (showHex)
import Kore.Util (showHashHex)
import Prettyprinter (Pretty, pretty)

newtype Logger a = Logger (a -> IO ())
Expand Down Expand Up @@ -97,9 +95,6 @@ withContext c = withLogger (\(Logger l) -> Logger $ l . (\(LogMessage ctxt m) ->

newtype TermCtxt = TermCtxt Int

showHashHex :: Int -> Text
showHashHex h = let w64 :: Word64 = fromIntegral h in Text.take 7 $ pack $ showHex w64 ""

instance ToLogFormat TermCtxt where
toTextualLog (TermCtxt hsh) = "term " <> (showHashHex hsh)

Expand Down
1 change: 1 addition & 0 deletions booster/library/Booster/Pattern/ApplyEquations.hs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ import Booster.Prettyprinter (renderDefault, renderOneLineText)
import Booster.SMT.Interface qualified as SMT
import Booster.Util (Bound (..), Flag (..))
import Kore.JsonRpc.Types.Log qualified as KoreRpcLog
import Kore.Util (showHashHex)

newtype EquationT io a
= EquationT (ReaderT EquationConfig (ExceptT EquationFailure (StateT EquationState io)) a)
Expand Down

Large diffs are not rendered by default.

77 changes: 47 additions & 30 deletions booster/tools/booster/Server.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import Control.Monad.Logger (
LoggingT (runLoggingT),
MonadLoggerIO (askLoggerIO),
ToLogStr (toLogStr),
defaultLoc,
runNoLoggingT,
)
import Control.Monad.Logger qualified as Logger
Expand All @@ -37,6 +36,7 @@ import Data.Text.Encoding qualified as Text (decodeUtf8)
import Options.Applicative
import System.Clock (
Clock (..),
TimeSpec (..),
getTime,
)
import System.Environment qualified as Env
Expand Down Expand Up @@ -72,21 +72,25 @@ import Kore.JsonRpc.Error hiding (Aborted, error)
import Kore.JsonRpc.Server
import Kore.JsonRpc.Types (API, HaltReason (..), ReqOrRes (Req, Res))
import Kore.JsonRpc.Types.Depth (Depth (..))
import Kore.Log (
import Kore.Log.BoosterAdaptor (
ExeName (..),
KoreLogType (..),
LogAction (LogAction),
LogSomeActionData (..),
TimestampsSwitch (TimestampsDisable),
defaultKoreLogOptions,
koreSomeEntryLogAction,
renderJson,
renderOnelinePretty,
renderStandardPretty,
swappableLogger,
withLogger,
)
import Kore.Log qualified as Log
import Kore.Log.BoosterAdaptor qualified as Log
import Kore.Log.DebugSolver qualified as Log
import Kore.Log.Registry qualified as Log
import Kore.Rewrite.SMT.Lemma (declareSMTLemmas)
import Kore.Syntax.Definition (ModuleName (ModuleName), SentenceAxiom)
import Kore.Util (extractLogMessageContext)
import Options.SMT as KoreSMT (KoreSolverOptions (..), Solver (..))
import Prettyprinter qualified as Pretty
import Proxy (KoreServer (..), ProxyConfig (..))
Expand Down Expand Up @@ -115,6 +119,7 @@ main = do
, port
, llvmLibraryFile
, logLevels
, logFormat
, logTimeStamps
, logContexts
, notLogContexts
Expand All @@ -136,6 +141,7 @@ main = do
(logLevel, customLevels) = adjustLogLevels logLevels
globPatterns = map (Glob.compile . filter (\c -> not (c == '\'' || c == '"'))) logContexts
negGlobPatterns = map (Glob.compile . filter (\c -> not (c == '\'' || c == '"'))) notLogContexts
contexLoggingEnabled = not (null logContexts) || not (null notLogContexts)
levelFilter :: Logger.LogSource -> LogLevel -> Bool
levelFilter _source lvl =
lvl `elem` customLevels
Expand All @@ -145,8 +151,6 @@ main = do
&& any (flip Glob.match (Text.unpack l)) globPatterns
_ -> False
|| lvl >= logLevel && lvl <= LevelError
koreLogExtraLevels =
Set.unions $ mapMaybe (`Map.lookup` koreExtraLogs) customLevels
koreSolverOptions = translateSMTOpts smtOptions

mTimeCache <- if logTimeStamps then Just <$> (newTimeCache "%Y-%m-%d %T") else pure Nothing
Expand All @@ -165,39 +169,52 @@ main = do

monadLogger <- askLoggerIO

koreLogEntriesAsJsonSelector <-
if Logger.LevelOther "SimplifyJson" `elem` customLevels
then case Map.lookup (Logger.LevelOther "SimplifyJson") logLevelToKoreLogEntryMap of
Nothing -> do
Logger.logWarnNS
"proxy"
"Could not find out which Kore log entries correspond to the SimplifyJson level"
pure (const False)
Just koreSimplificationLogEntries -> pure (`elem` koreSimplificationLogEntries)
else pure (const False)
let koreLogRenderer = case logFormat of
Standard -> renderStandardPretty (ExeName "") (TimeSpec 0 0) TimestampsDisable
OneLine -> renderOnelinePretty (ExeName "") (TimeSpec 0 0) TimestampsDisable
Json -> renderJson (ExeName "") (TimeSpec 0 0) TimestampsDisable
koreLogLateFilter = case logFormat of
OneLine ->
if contexLoggingEnabled
then \txt ->
let contextStr = Text.unpack $ extractLogMessageContext txt
in -- FIXME: likely terrible performance! Use something that does not unpack Text
not (any (flip Glob.match contextStr) negGlobPatterns)
&& any (flip Glob.match contextStr) globPatterns
else const True
_ -> const True

koreLogEntries =
if contexLoggingEnabled
then -- context logging: enable all Proxy-required Kore log entries
Set.unions . Map.elems $ koreExtraLogs
else -- no context logging: only enable Kore log entries for the given Proxy log levels
Set.unions . mapMaybe (`Map.lookup` koreExtraLogs) $ customLevels

koreLogActions :: forall m. MonadIO m => [LogAction m Log.SomeEntry]
koreLogActions = [koreLogAction]
where
koreLogAction =
koreSomeEntryLogAction
koreLogRenderer
(const True)
koreLogLateFilter
( LogAction $ \txt -> liftIO $
case mFileLogger of
Just fileLogger -> fileLogger $ toLogStr $ txt <> "\n"
Nothing -> stderrLogger $ toLogStr $ txt <> "\n"
)

liftIO $ void $ withBugReport (ExeName "kore-rpc-booster") BugReportOnError $ \_reportDirectory -> withMDLib llvmLibraryFile $ \mdl -> do
let coLogLevel = fromMaybe Log.Info $ toSeverity logLevel
koreLogOptions =
(defaultKoreLogOptions (ExeName "") startTime)
{ Log.logLevel = coLogLevel
, Log.logEntries = koreLogExtraLevels
, Log.logEntries = koreLogEntries
, Log.timestampsSwitch = TimestampsDisable
, Log.debugSolverOptions =
Log.DebugSolverOptions . fmap (<> ".kore") $ smtOptions >>= (.transcript)
, Log.logType =
LogSomeAction $
LogSomeActionData
{ entrySelector = koreLogEntriesAsJsonSelector
, standardLogAction =
(LogAction $ \txt -> liftIO $ monadLogger defaultLoc "kore" logLevel $ toLogStr txt)
, jsonLogAction =
( LogAction $ \txt -> liftIO $
case mFileLogger of
Just fileLogger -> fileLogger $ toLogStr $ txt <> "\n"
Nothing -> stderrLogger $ toLogStr $ "[SimplifyJson] " <> txt <> "\n"
)
}
, Log.logType = LogProxy (mconcat koreLogActions)
, Log.logFormat = Log.Standard
}
srvSettings = serverSettings port "*"
Expand Down
Loading