Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Metabase
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Engineering Digital Service
Metabase
Commits
68a15a35
Unverified
Commit
68a15a35
authored
5 years ago
by
Cam Saul
Committed by
GitHub
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Support NO_COLOR env var. pprint-to-str perf improvements (#11950)
parent
972435fb
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/metabase/util.clj
+24
-16
24 additions, 16 deletions
src/metabase/util.clj
with
24 additions
and
16 deletions
src/metabase/util.clj
+
24
−
16
View file @
68a15a35
...
...
@@ -207,28 +207,33 @@
identity
(
constantly
""
)))
(
def
^
:private
^
{
:arglists
'
([
color-symb
x
])}
colorize
"Colorize string `x` with the function matching `color` symbol or keyword, but only if `MB_COLORIZE_LOGS` is
enabled (the default)."
(
if
(
config/config-bool
:mb-colorize-logs
)
(
def
^
:private
colorize?
;; As of 0.35.0 we support the NO_COLOR env var. See https://no-color.org/ (But who hates color logs?)
(
if
(
config/config-str
:no-color
)
false
(
config/config-bool
:mb-colorize-logs
)))
(
def
^
{
:arglists
'
(
^
String
[
color-symb
x
])}
colorize
"Colorize string `x` using `color`, a symbol or keyword, but only if `MB_COLORIZE_LOGS` is enabled (the default).
`color` can be `green`, `red`, `yellow`, `blue`, `cyan`, `magenta`, etc. See the entire list of avaliable
colors [here](https://github.com/ibdknox/colorize/blob/master/src/colorize/core.clj)"
(
if
colorize?
(
fn
[
color
x
]
(
colorize/color
(
keyword
color
)
x
))
(
colorize/color
(
keyword
color
)
(
str
x
)
))
(
fn
[
_
x
]
x
)))
(
str
x
)
)))
(
defn
format-color
"Like `format`, but colorizes the output. `color` should be a symbol or keyword like `green`, `red`, `yellow`, `blue`,
`cyan`, `magenta`, etc. See the entire list of avaliable
colors [here](https://github.com/ibdknox/colorize/blob/master/src/colorize/core.clj).
"With one arg, converts something to a string and colorizes it. With two args, behaves like `format`, but colorizes
the output.
(format-color :red \"
Fatal error: %s\" error-message
)"
{
:style/indent
2
}
(format-color :red \"
%d cans\" 2
)"
{
:arglists
'
(
^
String
[
color
x
]
^
String
[
color
format-string
&
args
])
,
:style/indent
2
}
(
^
String
[
color
x
]
{
:pre
[((
some-fn
symbol?
keyword?
)
color
)]}
(
colorize
color
(
str
x
)))
(
colorize
color
x
))
(
^
String
[
color
format-str
ing
&
args
]
(
colorize
color
(
apply
format
(
str
format-str
ing
)
args
))))
(
^
String
[
color
format-str
&
args
]
(
colorize
color
(
apply
format
format-str
args
))))
(
defn
pprint-to-str
"Returns the output of pretty-printing `x` as a string.
...
...
@@ -239,7 +244,10 @@
{
:style/indent
1
}
(
^
String
[
x
]
(
when
x
(
with-out-str
(
pprint
x
))))
(
with-open
[
w
(
java.io.StringWriter.
)]
(
pprint
x
w
)
(
str
w
))))
(
^
String
[
color-symb
x
]
(
colorize
color-symb
(
pprint-to-str
x
))))
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment