Skip to contents

vcr log file setup

Usage

vcr_log_file(file, overwrite = TRUE)

vcr_log_info(message, include_date = TRUE)

Arguments

file

(character) a file path, required

overwrite

(logical) whether or not to overwrite the file at 'file' if it already exists. Default: TRUE

message

(character) a message to log

include_date

(logical) include date and time in each log entry. Default: FALSE

Examples

# user workflow
vcr_configuration()
#> <vcr configuration>
#>   Cassette Dir: /tmp/RtmplV3bmA
#>   Record: all
#>   Serialize with: yaml
#>   URI Parser: crul::url_parse
#>   Match Requests on: method, uri
#>   Preserve Bytes?: FALSE
#>   Logging?: FALSE
#>   ignored hosts: google.com
#>   ignore localhost?: TRUE
#>   Write disk path: 
logfile <- file.path(tempdir(), "vcr.log")
vcr_configure(dir = tempdir(), log = TRUE, log_opts = list(file = logfile))
#> <vcr configuration>
#>   Cassette Dir: /tmp/RtmplV3bmA
#>   Record: all
#>   Serialize with: yaml
#>   URI Parser: crul::url_parse
#>   Match Requests on: method, uri
#>   Preserve Bytes?: FALSE
#>   Logging?: TRUE (/tmp/RtmplV3bmA/vcr.log)
#>   ignored hosts: google.com
#>   ignore localhost?: TRUE
#>   Write disk path: 

readLines(logfile) # empty
#> character(0)

# log messages
vcr_log_info("hello world!")
readLines(logfile)
#> [1] "[Cassette: '<none>'] - 2024-10-25 05:33:15.34635 - hello world!"
vcr_log_info("foo bar")
readLines(logfile)
#> [1] "[Cassette: '<none>'] - 2024-10-25 05:33:15.34635 - hello world!"
#> [2] "[Cassette: '<none>'] - 2024-10-25 05:33:15.347457 - foo bar"    
## many messages
vcr_log_info(c("brown cow", "blue horse"))
readLines(logfile)
#> [1] "[Cassette: '<none>'] - 2024-10-25 05:33:15.34635 - hello world!"
#> [2] "[Cassette: '<none>'] - 2024-10-25 05:33:15.347457 - foo bar"    
#> [3] "[Cassette: '<none>'] - 2024-10-25 05:33:15.348583 - brown cow"  
#> [4] "[Cassette: '<none>'] - 2024-10-25 05:33:15.348583 - blue horse" 
vcr_log_info(c("brown cow", "blue horse", "green goat"))
readLines(logfile)
#> [1] "[Cassette: '<none>'] - 2024-10-25 05:33:15.34635 - hello world!"
#> [2] "[Cassette: '<none>'] - 2024-10-25 05:33:15.347457 - foo bar"    
#> [3] "[Cassette: '<none>'] - 2024-10-25 05:33:15.348583 - brown cow"  
#> [4] "[Cassette: '<none>'] - 2024-10-25 05:33:15.348583 - blue horse" 
#> [5] "[Cassette: '<none>'] - 2024-10-25 05:33:15.34975 - brown cow"   
#> [6] "[Cassette: '<none>'] - 2024-10-25 05:33:15.34975 - blue horse"  
#> [7] "[Cassette: '<none>'] - 2024-10-25 05:33:15.34975 - green goat"  

# standalone workflow
# set a file to log to
vcr_log_file((f <- tempfile()))
#> [1] TRUE
readLines(f) # empty
#> character(0)

# log messages
vcr_log_info("hello world!")
readLines(logfile)
#> [1] "[Cassette: '<none>'] - 2024-10-25 05:33:15.34635 - hello world!"
#> [2] "[Cassette: '<none>'] - 2024-10-25 05:33:15.347457 - foo bar"    
#> [3] "[Cassette: '<none>'] - 2024-10-25 05:33:15.348583 - brown cow"  
#> [4] "[Cassette: '<none>'] - 2024-10-25 05:33:15.348583 - blue horse" 
#> [5] "[Cassette: '<none>'] - 2024-10-25 05:33:15.34975 - brown cow"   
#> [6] "[Cassette: '<none>'] - 2024-10-25 05:33:15.34975 - blue horse"  
#> [7] "[Cassette: '<none>'] - 2024-10-25 05:33:15.34975 - green goat"  
vcr_log_info("foo bar")
readLines(logfile)
#> [1] "[Cassette: '<none>'] - 2024-10-25 05:33:15.34635 - hello world!"
#> [2] "[Cassette: '<none>'] - 2024-10-25 05:33:15.347457 - foo bar"    
#> [3] "[Cassette: '<none>'] - 2024-10-25 05:33:15.348583 - brown cow"  
#> [4] "[Cassette: '<none>'] - 2024-10-25 05:33:15.348583 - blue horse" 
#> [5] "[Cassette: '<none>'] - 2024-10-25 05:33:15.34975 - brown cow"   
#> [6] "[Cassette: '<none>'] - 2024-10-25 05:33:15.34975 - blue horse"  
#> [7] "[Cassette: '<none>'] - 2024-10-25 05:33:15.34975 - green goat"  

# cleanup
unlink(f)
unlink(logfile)