@@ -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,44 @@ 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 ), .topenv = parent.frame(), .timestamp = Sys.time() ) {
397+ log_level(FATAL , ... , namespace = namespace , .logcall = .logcall , .topcall = .topcall , .topenv = .topenv , .timestamp = .timestamp )
390398}
391399# ' @export
392400# ' @rdname log_level
393401log_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 )
402+ .logcall = sys.call(), .topcall = sys.call(- 1 ), .topenv = parent.frame(), .timestamp = Sys.time() ) {
403+ log_level(ERROR , ... , namespace = namespace , .logcall = .logcall , .topcall = .topcall , .topenv = .topenv , .timestamp = .timestamp )
396404}
397405# ' @export
398406# ' @rdname log_level
399407log_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 )
408+ .logcall = sys.call(), .topcall = sys.call(- 1 ), .topenv = parent.frame(), .timestamp = Sys.time() ) {
409+ log_level(WARN , ... , namespace = namespace , .logcall = .logcall , .topcall = .topcall , .topenv = .topenv , .timestamp = .timestamp )
402410}
403411# ' @export
404412# ' @rdname log_level
405413log_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 )
414+ .logcall = sys.call(), .topcall = sys.call(- 1 ), .topenv = parent.frame(), .timestamp = Sys.time() ) {
415+ log_level(SUCCESS , ... , namespace = namespace , .logcall = .logcall , .topcall = .topcall , .topenv = .topenv , .timestamp = .timestamp )
408416}
409417# ' @export
410418# ' @rdname log_level
411419log_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 )
420+ .logcall = sys.call(), .topcall = sys.call(- 1 ), .topenv = parent.frame(), .timestamp = Sys.time() ) {
421+ log_level(INFO , ... , namespace = namespace , .logcall = .logcall , .topcall = .topcall , .topenv = .topenv , .timestamp = .timestamp )
414422}
415423# ' @export
416424# ' @rdname log_level
417425log_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 )
426+ .logcall = sys.call(), .topcall = sys.call(- 1 ), .topenv = parent.frame(), .timestamp = Sys.time() ) {
427+ log_level(DEBUG , ... , namespace = namespace , .logcall = .logcall , .topcall = .topcall , .topenv = .topenv , .timestamp = .timestamp )
420428}
421429# ' @export
422430# ' @rdname log_level
423431log_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 )
432+ .logcall = sys.call(), .topcall = sys.call(- 1 ), .topenv = parent.frame(), .timestamp = Sys.time() ) {
433+ log_level(TRACE , ... , namespace = namespace , .logcall = .logcall , .topcall = .topcall , .topenv = .topenv , .timestamp = .timestamp )
426434}
427435
428436
0 commit comments