Gilead-BioStats / gsm

Good Statistical Monitoring R Package
https://gilead-biostats.github.io/gsm/
Apache License 2.0
39 stars 9 forks source link

Closes #1933 introduces logging capabilities to gsm #1939

Open zdz2101 opened 1 week ago

zdz2101 commented 1 week ago

Overview

implement log4r

Test Notes/Sample Code

Connected Issues

zdz2101 commented 1 week ago

@lauramaxwell @samussiah @dpastoor

Easiest way to demo what I've done is swapping out lines 48-63 of inst/examples/3_ReportingWorkflow.R with

# Step 1 - Create Mapped Data Layer - filter, aggregate and join raw data to create mapped data layer
mappings_wf <- MakeWorkflowList(strPath = "workflow/1_mappings")
SetLogger("mapping")
mapped <- RunWorkflows(mappings_wf, lRaw, strLogger = "mapping")

# Step 2 - Create Metrics - calculate metrics using mapped data
metrics_wf <- MakeWorkflowList(strPath = "workflow/2_metrics")
SetLogger("metrics")
analyzed <- RunWorkflows(metrics_wf, mapped, strLogger = "metrics")

# Step 3 - Create Reporting Layer - create reports using metrics data
reporting_wf <- MakeWorkflowList(strPath = "workflow/3_reporting")
SetLogger("reporting")
reporting <- RunWorkflows(reporting_wf,
                          c(mapped, list(lAnalyzed = analyzed,
                                         lWorkflows = metrics_wf)),
                          , strLogger = "reporting")

# Step 4 - Create KRI Reports - create KRI report using reporting data
module_wf <- MakeWorkflowList(strPath = "workflow/4_modules")
SetLogger("modules")
lReports <- RunWorkflows(module_wf, reporting, strLogger = "modules")

The code above will create 4 different logs. You can set the log, plug it into the strLogger argument and it will print the log toa file denoted as "xxx.log" where "xxx" is the name of put into SetLogger() . By default, on package load, the package already sets a default and will automatically log everything to a file called gsm.log too. Obviously, you can set it once, and feed all 4 RunWorkflows() calls into the same log, but for demostration purposes I thought something like this made sense to me.

To get additional information from a user session while they ran workflows, we can save a list of metadata objects (bunch of user environment information? R Version, pkg versions, etc.) when "setting" the logger and retrieve it with GetLogger() as well

Other things worth discussing: