julia> using Logging
julia> function wrap(f)
(a,b) -> begin
@info a
@info "c=$(b^2)"
f(a,b)
end
end
wrap (generic function with 1 method)
julia> f(a,b) = a+b
f (generic function with 1 method)
julia> wf = wrap(f)
#1 (generic function with 1 method)
julia> wf(2,3)
[ Info: 2
[ Info: c=9
5
Sorry but it’s not what I wanted.
I would like “not to” rewrite some logging lines (e.g., a or c = b^2) for logging.
I hope that just putting a macro @log in front of a variable that I want to log in my_func.
write a function (in the above example, my_func) which contains @log macro to indicate which variable will be saved.
passing a function (namely, Generator) so that Generator(my_func) produces a function like
function my_func2(a, b) # the same arguments with `my_func`
"""
the below lines would be the same as `my_func`; not manually written, but probably written by `Generator` and assisted by `@log`.
"""
a = a
c = b^2
# output is a dictionary containing variables annotated by `@log`
Dict(:a => a, :c => c)
end
That is, @log indicates which variable will be saved, and Generator will automatically transform my_func to my_func2 (recognising @log).
Actually, I’m not sure the above idea works properly. It’s just an idea