@@ -51,7 +51,8 @@ logger <- function(threshold, formatter, layout, appender) {
5151 force(appender )
5252
5353 function (level , ... , namespace = NA_character_ ,
54- .logcall = sys.call(), .topcall = sys.call(- 1 ), .topenv = parent.frame()) {
54+ .logcall = sys.call(), .topcall = sys.call(- 1 ),
55+ .topenv = parent.frame(), .timestamp = Sys.time()) {
5556 res <- list (
5657 level = level ,
5758 namespace = namespace ,
@@ -83,7 +84,10 @@ logger <- function(threshold, formatter, layout, appender) {
8384 res $ record <- layout(
8485 level , res $ message ,
8586 namespace = namespace ,
86- .logcall = substitute(.logcall ), .topcall = substitute(.topcall ), .topenv = .topenv
87+ .logcall = substitute(.logcall ),
88+ .topcall = substitute(.topcall ),
89+ .topenv = .topenv ,
90+ .timestamp = .timestamp
8791 )
8892
8993 appender(res $ record )
@@ -307,6 +311,8 @@ log_indices <- function(namespace = "global") {
307311# ' @param .topenv original frame of the `.topcall` calling function
308312# ' where the formatter function will be evaluated and that is used
309313# ' to look up the `namespace` as well via `logger:::top_env_name`
314+ # ' @param .timestamp The time the logging occured. Defaults to the current time
315+ # ' but may be overwritten if the logging is delayed from the time it happend
310316# ' @export
311317# ' @examples
312318# ' \dontshow{old <- logger:::namespaces_set()}
@@ -329,7 +335,8 @@ log_indices <- function(namespace = "global") {
329335# ' \dontshow{logger:::namespaces_set(old)}
330336# ' @return Invisible `list` of `logger` objects. See [logger()] for more details on the format.
331337log_level <- function (level , ... , namespace = NA_character_ ,
332- .logcall = sys.call(), .topcall = sys.call(- 1 ), .topenv = parent.frame()) {
338+ .logcall = sys.call(), .topcall = sys.call(- 1 ),
339+ .topenv = parent.frame(), .timestamp = Sys.time()) {
333340 # # guess namespace
334341 if (is.na(namespace )) {
335342 topenv <- top_env_name(.topenv )
@@ -354,6 +361,7 @@ log_level <- function(level, ..., namespace = NA_character_,
354361 NA
355362 }
356363 log_arg $ .topenv <- .topenv
364+ log_arg $ .timestamp <- .timestamp
357365 log_arg $ namespace <- namespace
358366
359367 invisible (lapply(definitions , function (definition ) {
@@ -385,44 +393,58 @@ validate_log_level <- function(level) {
385393# ' @export
386394# ' @rdname log_level
387395log_fatal <- function (... , namespace = NA_character_ ,
388- .logcall = sys.call(), .topcall = sys.call(- 1 ), .topenv = parent.frame()) {
389- log_level(FATAL , ... , namespace = namespace , .logcall = .logcall , .topcall = .topcall , .topenv = .topenv )
396+ .logcall = sys.call(), .topcall = sys.call(- 1 ),
397+ .topenv = parent.frame(), .timestamp = Sys.time()) {
398+ log_level(FATAL , ... , namespace = namespace , .logcall = .logcall ,
399+ .topcall = .topcall , .topenv = .topenv , .timestamp = .timestamp )
390400}
391401# ' @export
392402# ' @rdname log_level
393403log_error <- function (... , namespace = NA_character_ ,
394- .logcall = sys.call(), .topcall = sys.call(- 1 ), .topenv = parent.frame()) {
395- log_level(ERROR , ... , namespace = namespace , .logcall = .logcall , .topcall = .topcall , .topenv = .topenv )
404+ .logcall = sys.call(), .topcall = sys.call(- 1 ),
405+ .topenv = parent.frame(), .timestamp = Sys.time()) {
406+ log_level(ERROR , ... , namespace = namespace , .logcall = .logcall ,
407+ .topcall = .topcall , .topenv = .topenv , .timestamp = .timestamp )
396408}
397409# ' @export
398410# ' @rdname log_level
399411log_warn <- function (... , namespace = NA_character_ ,
400- .logcall = sys.call(), .topcall = sys.call(- 1 ), .topenv = parent.frame()) {
401- log_level(WARN , ... , namespace = namespace , .logcall = .logcall , .topcall = .topcall , .topenv = .topenv )
412+ .logcall = sys.call(), .topcall = sys.call(- 1 ),
413+ .topenv = parent.frame(), .timestamp = Sys.time()) {
414+ log_level(WARN , ... , namespace = namespace , .logcall = .logcall ,
415+ .topcall = .topcall , .topenv = .topenv , .timestamp = .timestamp )
402416}
403417# ' @export
404418# ' @rdname log_level
405419log_success <- function (... , namespace = NA_character_ ,
406- .logcall = sys.call(), .topcall = sys.call(- 1 ), .topenv = parent.frame()) {
407- log_level(SUCCESS , ... , namespace = namespace , .logcall = .logcall , .topcall = .topcall , .topenv = .topenv )
420+ .logcall = sys.call(), .topcall = sys.call(- 1 ),
421+ .topenv = parent.frame(), .timestamp = Sys.time()) {
422+ log_level(SUCCESS , ... , namespace = namespace , .logcall = .logcall ,
423+ .topcall = .topcall , .topenv = .topenv , .timestamp = .timestamp )
408424}
409425# ' @export
410426# ' @rdname log_level
411427log_info <- function (... , namespace = NA_character_ ,
412- .logcall = sys.call(), .topcall = sys.call(- 1 ), .topenv = parent.frame()) {
413- log_level(INFO , ... , namespace = namespace , .logcall = .logcall , .topcall = .topcall , .topenv = .topenv )
428+ .logcall = sys.call(), .topcall = sys.call(- 1 ),
429+ .topenv = parent.frame(), .timestamp = Sys.time()) {
430+ log_level(INFO , ... , namespace = namespace , .logcall = .logcall ,
431+ .topcall = .topcall , .topenv = .topenv , .timestamp = .timestamp )
414432}
415433# ' @export
416434# ' @rdname log_level
417435log_debug <- function (... , namespace = NA_character_ ,
418- .logcall = sys.call(), .topcall = sys.call(- 1 ), .topenv = parent.frame()) {
419- log_level(DEBUG , ... , namespace = namespace , .logcall = .logcall , .topcall = .topcall , .topenv = .topenv )
436+ .logcall = sys.call(), .topcall = sys.call(- 1 ),
437+ .topenv = parent.frame(), .timestamp = Sys.time()) {
438+ log_level(DEBUG , ... , namespace = namespace , .logcall = .logcall ,
439+ .topcall = .topcall , .topenv = .topenv , .timestamp = .timestamp )
420440}
421441# ' @export
422442# ' @rdname log_level
423443log_trace <- function (... , namespace = NA_character_ ,
424- .logcall = sys.call(), .topcall = sys.call(- 1 ), .topenv = parent.frame()) {
425- log_level(TRACE , ... , namespace = namespace , .logcall = .logcall , .topcall = .topcall , .topenv = .topenv )
444+ .logcall = sys.call(), .topcall = sys.call(- 1 ),
445+ .topenv = parent.frame(), .timestamp = Sys.time()) {
446+ log_level(TRACE , ... , namespace = namespace , .logcall = .logcall ,
447+ .topcall = .topcall , .topenv = .topenv , .timestamp = .timestamp )
426448}
427449
428450
0 commit comments