add_journal.Rd
The function manages the log information for tasks that need to be linked to each other. While the information is stored as a data.frame, it is presented or saved as formatted character when asked to be presented (for instance when verbose is set to TRUE).
add_journal(journal, task, status, id, degree = 0, verbose = TRUE)
data.frame, journal to be amended. May be missing (see details).
character, description of the task. May be missing (see details).
character, description of how the task has been performed. May be missing (see details).
integer, row of the task to be amended. May be missing (see details).
integer, indicates how deep is the task
logical, should a message be sent. Default to TRUE.
a data frame of journal information.
If the parameter 'journal' is missing, add_journal
creates an
empty journal (a data.frame with the expected format). The data.frame have
5 columns: 'start', 'end', 'task', 'status', 'degree', and 'elapsed'.
If the parameter 'task' is not missing, and if no 'status' is given,
add_journal
adds a new line to journal, and sets 'start' to
current time, 'task' to given 'task'.
If the parameter 'status' is not missing, add_journal
try to find
to which 'task' this is relevant. This can be done by giving explictly the
'id', or by ginving the 'task'. If nothing is given, it is supposed that it
corresponds with the the last task with missing 'status'. For found 'task',
it sets 'status' to given 'status', 'end' to current time. 'elapsed' to the
formatted difftime between 'end' and 'start' with floodam.data::fmt
.
If verbose == TRUE, a message is sent. If 'task' is given, a new line is
sent, but not ended by 'EOL'. When 'status' is given, message depend on what
was sent just before. If the last message was announcing the start of the
current task, it is completed with status and elapsed time. If not, a new
line is sent with the whole information (start, task, status, elapsed).
'degree' is used to have some tabular formatting. The message sent is
formatted by floodam.date:::format_journal
.
add_journal()
#> [1] task status start end elapsed
#> <0 rows> (or 0-length row.names)
add_journal(status = "Nothing to be done...", verbose = FALSE)
#> Warning: Trying to add status information to an empty journal.
#> [1] task status start end elapsed
#> <0 rows> (or 0-length row.names)
{
journal = add_journal(
task = sprintf(
"maintain gaspar with floodam.data (%s)",
utils::packageVersion("floodam.data")
)
)
Sys.sleep(.1)
journal = add_journal(journal, task = "download_gaspar", degree = 1)
journal = add_journal(journal, task = "adapt_gaspar", degree = 1)
Sys.sleep(.1)
journal = add_journal(journal, task = "alert_gaspar", degree = 1)
journal = add_journal(journal, status = "Done", id = 2)
Sys.sleep(.1)
journal = add_journal(journal, status = "Done", task = "alert_gaspar")
journal = add_journal(journal, status = "Done")
journal = add_journal(journal, status = "Done")
journal
}
#>
#> 2023-05-02 08:25:34.848778: [1] maintain gaspar with floodam.data (0.9.36.0)...
#>
#> 2023-05-02 08:25:34.95289: [2] download_gaspar...
#>
#> 2023-05-02 08:25:34.956625: [3] adapt_gaspar...
#>
#> 2023-05-02 08:25:35.060033: [4] alert_gaspar...
#>
#> 2023-05-02 08:25:34.95289: [2] download_gaspar... Done [00:00:00:00.11]
#>
#> 2023-05-02 08:25:35.060033: [4] alert_gaspar... Done [00:00:00:00.11]
#>
#> 2023-05-02 08:25:34.956625: [3] adapt_gaspar... Done [00:00:00:00.21]
#>
#> 2023-05-02 08:25:34.848778: [1] maintain gaspar with floodam.data (0.9.36.0)... Done [00:00:00:00.32]
#> start end
#> 1 2023-05-02 08:25:34 2023-05-02 08:25:35
#> 2 2023-05-02 08:25:34 2023-05-02 08:25:35
#> 3 2023-05-02 08:25:34 2023-05-02 08:25:35
#> 4 2023-05-02 08:25:35 2023-05-02 08:25:35
#> task status degree elapsed
#> 1 maintain gaspar with floodam.data (0.9.36.0) Done 0 00:00:00:00.32
#> 2 download_gaspar Done 1 00:00:00:00.11
#> 3 adapt_gaspar Done 1 00:00:00:00.21
#> 4 alert_gaspar Done 1 00:00:00:00.11