Capturing logger output inside a method

后端 未结 2 815
有刺的猬
有刺的猬 2021-02-10 14:57

New to Ruby I have a simple driver script right now that runs multiple test scripts in other ruby files. I have a method called RunScript() that runs the test scripts. The log

2条回答
  •  北恋
    北恋 (楼主)
    2021-02-10 15:43

    Indeed there is no way to get the content of the logger without importing extra things. Here is a different solution. Because logger has only several logging methods you may simply make your own and log and collect logs in that function

       #the_logger - regular logger
       #the_arr - a global array to keep your logs in
       #the_string - log string
    
       def log_info(the_logger, the_arr, the_string)
    
           the_logger.info(the_string);
           the_arr.push(the_string);
       end
       .....................and use global the_arr to get your output
    

    Do this for 'debug', 'info', 'fatal' this is a simple way to use your log outputs as you run your program

提交回复
热议问题