@@ -163,11 +163,11 @@ const AboveMaxLevel = LogLevel( 1000001)
163
163
const _min_enabled_level = Ref {LogLevel} (Debug)
164
164
165
165
# add to this to dict to introduce a log level for printing
166
- # i.e. custom_log_levels[LogLevel(-500)] = ("MyLog" , :magenta)
167
- const custom_log_levels = Dict {LogLevel,Tuple{String ,Symbol}} ()
166
+ # i.e. custom_log_levels[LogLevel(-500)] = (:mylog , :magenta)
167
+ const custom_log_levels = Dict {LogLevel,Tuple{Symbol ,Symbol}} ()
168
168
169
169
function show (io:: IO , level:: LogLevel )
170
- if level in keys (custom_log_levels) print (io, custom_log_levels[level][1 ]:: String )
170
+ if level in keys (custom_log_levels) print (io, custom_log_levels[level][1 ])
171
171
elseif level == BelowMinLevel print (io, " BelowMinLevel" )
172
172
elseif level == Debug print (io, " Debug" )
173
173
elseif level == Info print (io, " Info" )
694
694
695
695
_global_logstate = LogState (SimpleLogger ())
696
696
697
+ """
698
+ create_log_macro(name::Symbol, level::Int, color::Union{Int,Symbol}=:default)
699
+ create_log_macro(name::Symbol, loglevel::LogLevel, color::Union{Int,Symbol}=:default)
700
+
701
+ Creates a custom log macro like `@info`, `@warn` etc. with a given `name`, `level` and
702
+ `color`. The macro created is named with the lowercase form of `name` but the given form
703
+ is used for the printing.
704
+
705
+ See `Base.text_colors` for recognized color values.
706
+
707
+ ```julia-repl
708
+ julia> create_log_macro(:MyLog, 200, :magenta)
709
+ @mylog (macro with 1 method)
710
+
711
+ julia> @mylog "hello"
712
+ [ MyLog: hello
713
+ ```
714
+ """
715
+ function create_log_macro (name:: Symbol , loglevel:: LogLevel , color:: Union{Int,Symbol} = :default )
716
+ haskey (Base. text_colors, color) || @warn " Color $(repr (color)) not recognized"
717
+ custom_log_levels[loglevel] = (name, color)
718
+ macro_name = Symbol (lowercase (string (name)))
719
+ @eval begin
720
+ macro $macro_name (exs... )
721
+ logmsg_code ((@_sourceinfo ). .. , $ loglevel, exs... )
722
+ end
723
+ end
724
+ end
725
+ create_log_macro (name:: Symbol , level:: Int , color:: Union{Int,Symbol} = :default ) =
726
+ create_log_macro (name, LogLevel (level), color)
727
+
697
728
end # CoreLogging
0 commit comments