verbose.jl 1007 B

123456789101112131415161718192021222324252627282930
  1. module verbose
  2. using Dates
  3. using Base.Printf: _printf, is_str_expr, fix_dec, DIGITS, DIGITSs, print_fixed, print_fixed_width, decode_dec, decode_hex,
  4. ini_hex, ini_HEX, print_exp_a, decode_0ct, decode_HEX, ini_dec, print_exp_e,
  5. decode_oct, _limit, SmallNumber
  6. export tprintf
  7. time_format = "HH:MM:SS"
  8. """
  9. tprintf(args...)
  10. Same as printf but with leading timestamps
  11. """
  12. function tprintf(args...)
  13. isempty(args) && throw(ArgumentError("tprintf: called with no arguments"))
  14. if isa(args[1], AbstractString) || is_str_expr(args[1])
  15. _printf("printf", :stdout, "[$(Dates.format(now(), time_format))] $(args[1])", args[2:end])
  16. else
  17. (length(args) >= 2 && (isa(args[2], AbstractString) || is_str_expr(args[2]))) ||
  18. throw(ArgumentError("tprintf: first or second argument must be a format string"))
  19. _printf("printf", esc(args[1]), "[$(Dates.format(now(), time_format))] $(args[2])", args[3:end])
  20. end
  21. end
  22. end # module verbose