Skip to content
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

Add colours to the LogOption constructor #222

Merged
merged 1 commit into from
Aug 5, 2020

Conversation

mpilgrem
Copy link
Member

The motivation for this pull request is that the exisitng hard-coded colours in RIO.Process.withProcessTimeLog and RIO.Prelude.Logger.simpleLogFunc (for timestamps and locs) are not visible when using the Solarised Dark theme.

Tested on Windows 10 by sucessfully rebuilding stack (which depends on rio), with and without making use of the option to customise logger colours.

The defaults are the same as what was previously hard-coded and RIO.Prelude.Logger does not export the constructor of LogOption, so existing code depending on rio should not be affected.

A new LogColors type is exported, and an associated accessor (logFuncColorsL):

data LogColors = LogColors
  { -- | The color associated with each 'LogLevel'.
    logColorLogLevels :: !(LogLevel -> Utf8Builder)
    -- | The color of secondary content.
  , logColorSecondary :: !Utf8Builder
    -- | The color of accents, which are indexed by 'Int'.
  , logColorAccents :: !(Int -> Utf8Builder)
  }

timestamps and locs in simpleLogFunc use the colour of secondary content. withProcessTimeLog uses accent colour 0 to highlight the duration time.

mpilgrem added a commit to mpilgrem/rio-prettyprint that referenced this pull request Aug 1, 2020
Add styles `Info`, `Debug`, `OtherLevel`, `Secondary` and `Highlight` to type `Style`, that correspond to:

(1) constructors of `RIO.Prelude.Logger.LogLevel` not currently catered for, namely `LevelInfo`, `LevelDebug` and `LevelOther !Text`. These constructors determine styles (currently hard-coded) used by `RIO.Prelude.Logger.simpleLogFunc`; and

(2) styles (currently hard-coded) used by `RIO.Prelude.Logger.simpleLogFunc` (for timestamps and locs, treated as secondary content) and `RIO.Process.withProcessTimeLog` (to highlight process duration).

The defaults for the additons, in `RIO.PrettyPrint.DefaultStyles`, are the hard-coded styles used in `RIO.Prelude.Logger.simpleLogFunc` and `RIO.Process.withProcessTimeLog`.

The additions do not change the order of the existing constructors of `Style`.

Code documentation for the new styles is included and the code document for existing styles is extended or tidied-up.

The motivation for these changes is explained in commercialhaskell/rio#222.
@mpilgrem
Copy link
Member Author

mpilgrem commented Aug 2, 2020

Since my original pull request, I have changed the type in the three setLog... functions from Text to Utf8Builder. Originally, I reasoned that Text was a more user-friendly type for those functions but now I think that it is wrong to impose the Text -> Utf8Builder overhead on all users.

The motivation for this is that the exisitng hard-coded colours in `RIO.Process.withProcessTimeLog` and `RIO.Prelude.Logger.simpleLogFunc` (for timestamps and locs) are not visible when using the Solarised Dark theme.

Tested on Windows 10 by sucessfully rebuilding `stack` (which depends on `rio`), with and without making use of the option to customise logger colours.

The defaults are the same as what was previously hard-coded, so existing code depending on `rio` should not be affected.

A new `LogColors` type is defined but not exported, and three associated accessors are exported (`logFuncLogLevelColorsL`, `logFuncSecondaryColorL` and `logFuncAccentColorsL`):

```haskell
data LogColors = LogColors
  { -- | The color associated with each 'LogLevel'.
    logColorLogLevels :: !(LogLevel -> Utf8Builder)
    -- | The color of secondary content.
  , logColorSecondary :: !Utf8Builder
    -- | The color of accents, which are indexed by 'Int'.
  , logColorAccents :: !(Int -> Utf8Builder)
  }
```

timestamps and locs in `simpleLogFunc` use the colour of secondary content. `withProcessTimeLog` uses accent colour 0 to highlight the duration time.
mpilgrem added a commit to mpilgrem/rio-prettyprint that referenced this pull request Aug 3, 2020
Add styles `Info`, `Debug`, `OtherLevel`, `Secondary` and `Highlight` to type `Style`, that correspond to:

(1) constructors of `RIO.Prelude.Logger.LogLevel` not currently catered for, namely `LevelInfo`, `LevelDebug` and `LevelOther !Text`. These constructors determine styles (currently hard-coded) used by `RIO.Prelude.Logger.simpleLogFunc`; and

(2) styles (currently hard-coded) used by `RIO.Prelude.Logger.simpleLogFunc` (for timestamps and locs, treated as secondary content) and `RIO.Process.withProcessTimeLog` (to highlight process duration).

The defaults for the additons, in `RIO.PrettyPrint.DefaultStyles`, are the hard-coded styles used in `RIO.Prelude.Logger.simpleLogFunc` and `RIO.Process.withProcessTimeLog`.

The additions do not change the order of the existing constructors of `Style`.

Code documentation for the new styles is included and the code document for existing styles is extended or tidied-up.

The motivation for these changes is explained in commercialhaskell/rio#222.
@snoyberg snoyberg merged commit abaaceb into commercialhaskell:master Aug 5, 2020
@mpilgrem mpilgrem deleted the logColors branch August 5, 2020 12:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants