1
1
mirror of https://github.com/github/semantic.git synced 2024-12-22 06:11:49 +03:00

Autodetect print source

This commit is contained in:
Timothy Clem 2017-08-01 15:05:25 -07:00
parent ec9fcc7007
commit da51cb3c20
2 changed files with 4 additions and 3 deletions

View File

@ -70,9 +70,9 @@ terminalFormatter Options{..} (Message level message pairs time) =
data Options = Options
{ optionsEnableColour :: Bool -- ^ Whether to enable colour formatting for logging (Only works when logging to a terminal that supports ANSI colors).
, optionsLevel :: Maybe Level -- ^ What level of messages to log. 'Nothing' disabled logging.
, optionsPrintSource :: Bool -- ^ Whether to print the source reference when logging errors.
, optionsRequestID :: Maybe String -- ^ Optional request id for tracing across systems.
, optionsIsTerminal :: Bool -- ^ Whether a terminal is attached (set automaticaly at runtime).
, optionsPrintSource :: Bool -- ^ Whether to print the source reference when logging errors (set automatically at runtime).
, optionsFormatter :: Options -> Message -> String -- ^ Log formatter to use (set automaticaly at runtime).
, optionsProcessID :: CPid -- ^ ProcessID (set automaticaly at runtime).
}
@ -81,9 +81,9 @@ defaultOptions :: Options
defaultOptions = Options
{ optionsEnableColour = True
, optionsLevel = Just Warning
, optionsPrintSource = False
, optionsRequestID = Nothing
, optionsIsTerminal = False
, optionsPrintSource = False
, optionsFormatter = logfmtFormatter
, optionsProcessID = 0
}
@ -95,6 +95,7 @@ configureOptionsForHandle handle options = do
pure $ options
{ optionsIsTerminal = isTerminal
, optionsFormatter = if isTerminal then terminalFormatter else logfmtFormatter
, optionsPrintSource = isTerminal
, optionsProcessID = pid
}

View File

@ -44,10 +44,10 @@ arguments = info (version <*> helper <*> ((,) <$> optionsParser <*> argumentsPar
<$> (not <$> switch (long "disable-colour" <> long "disable-color" <> help "Disable ANSI colors in log messages even if the terminal is a TTY."))
<*> options [("error", Just Log.Error), ("warning", Just Log.Warning), ("info", Just Log.Info), ("debug", Just Log.Debug), ("none", Nothing)]
(long "log-level" <> value (Just Log.Warning) <> help "Log messages at or above this level, or disable logging entirely.")
<*> switch (long "print-source" <> help "Include source references in logged errors where applicable.")
<*> optional (strOption (long "request-id" <> help "A string to use as the request identifier for any logged messages." <> metavar "id"))
-- The rest of the logging options are set automatically at runtime.
<*> pure False -- IsTerminal
<*> pure False -- PrintSource
<*> pure Log.logfmtFormatter -- Formatter
<*> pure 0 -- ProcessID
argumentsParser = (. Task.writeToOutput) . (>>=)