Handling project specific variables for a library?

Dear community,

I am working on a numerical library. The following is only some style aspect, so nothing crucial: There are some variables/ routines which are needed for every function, and I wonder how I could simplify the code a little bit, since I am “hard-coding” everything at the moment. This is about

  • Logging: Yes or no, in what detail?
  • Caching: Should the outcome of the routine be saved/ loaded if available? If yes, what is the path?
  • Should there be a progress bar displayed for a loop in the routine?
  • Debugging: Should the routine run many checks and tests?
    For example, a typical routine looks like this (empty datapath means no caching)
function calc_y(x; loglevel=3, datapath="",debugging=false)
    pr(s,n) = n<loglevel ? println(s) : nothing
    filename = "test.h5"
    pr("Starting function calc_y...",0)
    if isfile(datapath*filename)
        # ... load ...
        # ... calc something ...
        z = calc_z(x,...,loglevel=loglevel, datapath=datapath, debugging=debugging) # call another function
        y = x + z
        if debugging
            if z < 0 
                throw("z is smaller than 0! That cannot work!")
        # ... calc more ...
        if datapath != ""
            # ... save to filename ...
    return y     

Basically, this “skeleton” looks the same in every function. Is there a way to simplify this?

I believe GitHub - JuliaPackaging/Preferences.jl: Project Preferences Package was made to facilitate having project-specific settings for packages