Skip to content
Snippets Groups Projects
Commit d4cbb947 authored by xo30xoqa's avatar xo30xoqa
Browse files

Set up logging functionality

parent fa324118
No related branches found
No related tags found
No related merge requests found
......@@ -2,7 +2,7 @@
julia_version = "1.8.2"
manifest_format = "2.0"
project_hash = "3094d3134b943670349bd9f535622ba576264330"
project_hash = "410e4f52e8705498e2b8e0db499b81897c7f31a9"
[[deps.AbstractFFTs]]
deps = ["ChainRulesCore", "LinearAlgebra"]
......
......@@ -9,5 +9,6 @@ ArgParse = "c7e460c6-2fb9-53a9-8c5b-16f535851c63"
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
GeoArrays = "2fb1d81b-e6a0-5fc5-82e6-8e06903437ab"
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
LoggingExtras = "e6f89c97-d47a-5376-807f-9c37f3926c36"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
TOML = "fa267f1f-6049-4f14-aa54-33bafae1ed76"
### Persephone - a socio-economic-ecological model of European agricultural landscapes.
###
### This is an example configuration file for development.
### Note: the reference version is at src/parameters.toml
###
[core]
configfile = "data/config.toml" # location of the configuration file
mapfile = "data/region_hohenlohe.tif" # location of the map file
outdir = "results" # location and name of the output folder
logfile = "simulation.log" # name of the log file
loglevel = "debug" # verbosity level: "debug", "normal", "errors"
runtime = 5 # duration in days that the simulation will run for
seed = 0 # seed value for the RNG (0 -> random value)
[farm]
[ecology]
[crop]
cropmodel = "linear" # crop growth model to use, "linear" or "aquacrop" (not yet implemented)
......@@ -18,6 +18,7 @@ using
Dates,
GeoArrays,
Logging,
LoggingExtras,
Random,
TOML
......
......@@ -83,10 +83,15 @@ end
Certain software parameters can be set via the commandline.
"""
function parsecommandline()
s = ArgParseSettings()
versionstring = """
Persephone $(@project_version), commit $(read(`git rev-parse HEAD`, String)[1:8])
© 2022 Daniel Vedder, Lea Kolb (MIT license)
https://git.idiv.de/xo30xoqa/persephone
"""
s = ArgParseSettings(add_version=true, version=versionstring)
@add_arg_table! s begin
"--configfile", "-c"
help = "name of the config file"
help = "name of the configuration file"
arg_type = String
required = false
"--seed", "-s"
......@@ -101,13 +106,13 @@ function parsecommandline()
arg_type = String
required = false
"--loglevel", "-l"
help = "verbosity: \"debug\", \"normal\", or \"errors\""
help = "verbosity: \"debug\", \"info\", or \"errors\""
arg_type = String
required = false
"--runtime", "-r"
help = "duration in days that the simulation will run"
arg_type = Int
required = false
help = "duration in days that the simulation will run"
arg_type = Int
required = false
end
args = parse_args(s)
for a in keys(args)
......
......@@ -3,7 +3,7 @@
### This file includes functions for saving the model output.
###
## Note: some of this code was adapted from the GeMM model by Leidinger et al.
## Note: `setupdatadir()` was adapted from the GeMM model by Leidinger et al.
## (https://github.com/CCTB-Ecomods/gemm/blob/master/src/output.jl)
"""
......@@ -22,6 +22,17 @@ function setupdatadir()
else
mkpath(param("core.outdir"))
end
# Setup the logging system and logfile
loglevel = Logging.Info
if param("core.loglevel") == "debug"
loglevel = Logging.Debug
elseif param("core.loglevel") == "quiet"
loglevel = Logging.Warn
end
logfile = open(joinpath(param("core.outdir"), "simulation.log"), "w+")
simulationlogger = TeeLogger(ConsoleLogger(logfile, loglevel),
ConsoleLogger(stdout, loglevel))
global_logger(simulationlogger)
@info "Setting up output directory $(param("core.outdir"))"
# Export a copy of the current parameter settings to the output folder.
# This can be used to replicate this exact run in future, and also
......@@ -35,6 +46,7 @@ function setupdatadir()
end
# Copy the map file to the output folder
mapf = param("core.mapfile")
!(isfile(mapf)) && @error "The map file $(mapf) doesn't exist."
!(isfile(mapf)) && Base.error("The map file $(mapf) doesn't exist.")
cp(mapf, joinpath(param("core.outdir"), basename(mapf)), force = true)
end
......@@ -8,15 +8,16 @@ function initsim(config::String)
Random.seed!(param("core.seed"))
setupdatadir()
#TODO create world
@info "Simulation initialised."
end
function stepsim()
println("Simulating another day.")
@info "Simulating another day."
#TODO
end
function finalisesim()
println("Simulation ran. Nothing happened. But it will!")
@info "Simulation ran. Nothing happened. But it will!"
#TODO
end
......
......@@ -10,8 +10,7 @@
configfile = "src/parameters.toml" # location of the configuration file
mapfile = "data/region_jena.tif" # location of the map file
outdir = "results" # location and name of the output folder
logfile = "simulation.log" # name of the log file
loglevel = "debug" # verbosity level: "debug", "normal", "errors"
loglevel = "debug" # verbosity level: "debug", "info", "quiet"
runtime = 10 # duration in days that the simulation will run for
seed = 0 # seed value for the RNG (0 -> random value)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment