Skip to content

Commit f4c8e38

Browse files
authored
Detect stderr ttyhascolor at init (#265)
1 parent 3dc35d2 commit f4c8e38

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/GPUCompiler.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,8 @@ include("reflection.jl")
4646
include("precompile.jl")
4747
_precompile_()
4848

49+
function __init__()
50+
STDERR_HAS_COLOR[] = get(stderr, :color, false)
51+
end
52+
4953
end # module

src/utils.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ end
2626

2727
using Logging
2828

29+
const STDERR_HAS_COLOR = Ref{Bool}(false)
30+
2931
# define safe loggers for use in generated functions (where task switches are not allowed)
3032
for level in [:debug, :info, :warn, :error]
3133
@eval begin
@@ -35,7 +37,7 @@ for level in [:debug, :info, :warn, :error]
3537
macrocall.args[1] = Symbol($"@$level")
3638
quote
3739
old_logger = global_logger()
38-
io = IOContext(Core.stderr, :color=>get(stderr, :color, false))
40+
io = IOContext(Core.stderr, :color=>STDERR_HAS_COLOR[])
3941
min_level = Logging.min_enabled_level(old_logger)
4042
global_logger(Logging.ConsoleLogger(io, min_level))
4143
ret = $(esc(macrocall))

0 commit comments

Comments
 (0)