当前位置: 首页 > 工具软件 > Log4r > 使用案例 >

r语言 利用log4r和trycatch收集异常日志例子

邹高峻
2023-12-01
#创建日志

# Import the log4r package.
library('log4r')

# Create a new logger object with create.logger().
logger <- create.logger()

# Set the logger's file output.
logfile(logger) <- 'peaktrainDebugging.log'

# Set the current level of the logger.
level(logger) <- 'INFO'


tryCatch({
          peaktrain(mp_id[x])
},warning = function(w){
          log4r::warn(logger, paste(mp_id[x],w,sep=' '))
}, error = function(e){
         log4r::error(logger, paste(mp_id[x],e,sep=' '))
}, finally = {

})
[ 2015-08-07 11:02:15 ] ERROR 57402 Error in peaktrain(mp_id[x]): not enough train data!

[ 2015-08-07 11:02:15 ] ERROR 601122208 Error in peaktrain(mp_id[x]): not enough train data!

[ 2015-08-07 11:02:16 ] ERROR 610073362 Error in peaktrain(mp_id[x]): not enough train data!

[ 2015-08-07 11:02:17 ] ERROR 2871 Error in peaktrain(mp_id[x]): not enough train data!

[ 2015-08-07 11:02:17 ] ERROR 121356 Error in peaktrain(mp_id[x]): not enough train data!

[ 2015-08-07 11:02:17 ] ERROR 510673877 Error in peaktrain(mp_id[x]): not enough train data!

[ 2015-08-07 11:02:18 ] ERROR 510674618 Error in peaktrain(mp_id[x]): not enough train data!

[ 2015-08-07 11:02:18 ] ERROR 510184634 Error in peaktrain(mp_id[x]): not enough train data!

[ 2015-08-07 11:02:18 ] ERROR 163800 Error in peaktrain(mp_id[x]): not enough train data!

[ 2015-08-07 11:02:19 ] ERROR 510669287 Error in peaktrain(mp_id[x]): not enough train data!

[ 2015-08-07 11:02:19 ] ERROR 130170 Error in peaktrain(mp_id[x]): not enough train data!

[ 2015-08-07 11:02:20 ] ERROR 611990529 Error in peaktrain(mp_id[x]): not enough train data!

[ 2015-08-07 11:02:20 ] ERROR 510677183 Error in peaktrain(mp_id[x]): not enough train data!

[ 2015-08-07 11:02:20 ] ERROR 610524655 Error in peaktrain(mp_id[x]): not enough train data!

[ 2015-08-07 11:02:21 ] ERROR 611638191 Error in peaktrain(mp_id[x]): not enough train data!

[ 2015-08-07 11:02:21 ] ERROR 610519417 Error in peaktrain(mp_id[x]): not enough train data!

[ 2015-08-07 11:02:21 ] ERROR 611782344 Error in peaktrain(mp_id[x]): not enough train data!

[ 2015-08-07 11:02:21 ] ERROR 611646198 Error in peaktrain(mp_id[x]): not enough train data!

[ 2015-08-07 11:02:22 ] ERROR 612671577 Error in peaktrain(mp_id[x]): not enough train data!

[ 2015-08-07 11:02:22 ] ERROR 600010861 Error in peaktrain(mp_id[x]): not enough train data!

[ 2015-08-07 11:02:23 ] ERROR 10025967 Error in peaktrain(mp_id[x]): not enough train data!

[ 2015-08-07 11:02:23 ] ERROR 510662534 Error in peaktrain(mp_id[x]): not enough train data!

[ 2015-08-07 11:02:23 ] ERROR 10018392 Error in peaktrain(mp_id[x]): not enough train data!

[ 2015-08-07 11:02:24 ] ERROR 510668828 Error in peaktrain(mp_id[x]): not enough train data!

[ 2015-08-07 11:02:24 ] ERROR 510676115 Error in peaktrain(mp_id[x]): not enough train data!

[ 2015-08-07 11:02:25 ] ERROR 10025424 Error in peaktrain(mp_id[x]): not enough train data!

[ 2015-08-07 11:02:25 ] ERROR 510669584 Error in peaktrain(mp_id[x]): not enough train data!
 类似资料: