log_time: Track time of code execution

Description Usage Arguments Details Value See Also Examples

Description

Track time of code execution in easy, efficient and nice looking way

Usage

1
2
3
log_time(message, level = 'DEBUG') %<% {
   expression
}

Arguments

message

A string describing context of code. Can't be empty.

level

A logging level. One of 'DEBUG', 'INFO', 'WARNING', 'ERROR'. Default is DEBUG.

Details

log_time has special call that requires using pipe operator %<%.

log_time can handle nested calls and returns execution times of nested parts as well as overall execution time. Besides, it makes script much more organized and readable.

By default, log_time will print messages to console. This can be overwritten by configure_logging or, if used inside logger context, by create_logger function.

Value

Start and End messages. Execution time is appended to the End message.

See Also

create_logger, %<%

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
# create a logtime with message 'Some text';
# default level is DEBUG
log_time('Some text') %<% {
   Sys.sleep(1)
}
# output:
# 2016-09-21 10:54:31 - DEBUG - [Start] - [Some text]
# 2016-09-21 10:54:32 - DEBUG - [End  ] - [Some text] - [Done in 1 sec. (0 min.)]


# create the same logtime with changed level to INFO
log_time('Some text', level = 'INFO') %<% {
   Sys.sleep(1)
}
# output:
# 2016-09-21 10:53:20 - INFO - [Start] - [Some text]
# 2016-09-21 10:53:21 - INFO - [End  ] - [Some text] - [Done in 1 sec. (0 min.)]

delta1epsilon/logtime documentation built on May 15, 2019, 3:22 a.m.