Quantcast
Channel: How can I have ruby logger log output to stdout as well as file? - Stack Overflow
Browsing all 23 articles
Browse latest View live

Answer by YujiSoftware for How can I have ruby logger log output to stdout as...

Use IO.popen with tee.Method: IO.popen — Documentation for core (3.0.2)$logger = Logger.new(IO.popen(["tee", "-a", "debug.log"], "wb"))

View Article



Answer by khiav reoy for How can I have ruby logger log output to stdout as...

You can inherit Logger and override the write method:class LoggerWithStdout < Logger def initialize(*) super def @logdev.write(msg) super puts msg end endendlogger =...

View Article

Answer by Agis for How can I have ruby logger log output to stdout as well as...

I also has this need recently so I implemented a library that does this. I just discovered this StackOverflow question, so I'm putting it out there for anyone that needs it:...

View Article

Answer by Tyler Rick for How can I have ruby logger log output to stdout as...

If you're okay with using ActiveSupport, then I would highly recommend checking out ActiveSupport::Logger.broadcast, which is an excellent and very concise way to add additional log destinations to a...

View Article

Answer by yegor256 for How can I have ruby logger log output to stdout as...

You can use Loog::Tee object from loog gem:require 'loog'logger = Loog::Tee.new(first, second)Exactly what you are looking for.

View Article


Answer by Charles Murphy for How can I have ruby logger log output to stdout...

This is a simplification of @rado's solution.def delegator(*methods) Class.new do def initialize(*targets) @targets = targets end methods.each do |m| define_method(m) do |*args| @targets.map { |t|...

View Article

Answer by wteuber for How can I have ruby logger log output to stdout as well...

I like the MultiIO approach. It works well with Ruby Logger. If you use pure IO it stops working because it lacks some methods that IO objects are expected to have. Pipes were mentioned before here:...

View Article

Answer by Jose Alban for How can I have ruby logger log output to stdout as...

Quick and dirty (ref: https://coderwall.com/p/y_b3ra/log-to-stdout-and-a-file-at-the-same-time)require 'logger'll=Logger.new('| tee script.log')ll.info('test')

View Article


Answer by Michael Voigt for How can I have ruby logger log output to stdout...

One more option ;-)require 'logger'class MultiDelegator def initialize(*targets) @targets = targets end def method_missing(method_sym, *arguments, &block) @targets.each do |target|...

View Article


Answer by Rado for How can I have ruby logger log output to stdout as well as...

@jonas054's answer above is great, but it pollutes the MultiDelegator class with every new delegate. If you use MultiDelegator several times, it will keep adding methods to the class, which is...

View Article

Answer by knut for How can I have ruby logger log output to stdout as well as...

Are you restricted to the standard logger?If not you may use log4r:require 'log4r'LOGGER = Log4r::Logger.new('mylog')LOGGER.outputters << Log4r::StdoutOutputter.new('stdout')LOGGER.outputters...

View Article

Answer by Igor for How can I have ruby logger log output to stdout as well as...

For those who like it simple:log = Logger.new("| tee test.log") # note the pipe ( '|' )log.info "hi" # will log to both STDOUT and test.logsourceOr print the message in the Logger formatter:log =...

View Article

Answer by retgoat for How can I have ruby logger log output to stdout as well...

One more way.If you're using tagged logging and need tags in another logfile as well, you could do it in this way# backported from rails4# config/initializers/active_support_logger.rbmodule...

View Article


Answer by phillbaker for How can I have ruby logger log output to stdout as...

If you're in Rails 3 or 4, as this blog post points out, Rails 4 has this functionality built in. So you can do:# config/environment/production.rbfile_logger =...

View Article

Answer by rupweb for How can I have ruby logger log output to stdout as well...

I think your STDOUT is used for critical runtime info and errors raised.So I use $log = Logger.new('process.log', 'daily')to log debug and regular logging, and then wrote a few puts "doing...

View Article


Answer by Patrick Hüsler for How can I have ruby logger log output to stdout...

I have written a little RubyGem that allows you to do several of these things:# Pipe calls to an instance of Ruby's logger class to $stdoutrequire 'teerb'log_file = File.open("debug.log", "a")logger =...

View Article

Answer by Jerska for How can I have ruby logger log output to stdout as well...

I went to the same idea of "Delegating all methods to sub-elements" that other people already explored, but am returning for each of them the return value of the last call of the method.If I didn't, it...

View Article


Answer by dsz for How can I have ruby logger log output to stdout as well as...

While I quite like the other suggestions, I found I had this same issue but wanted the ability to have different logging levels for STDERR and the file. I ended up with a routing strategy that...

View Article

Answer by Tyler Rick for How can I have ruby logger log output to stdout as...

Here's another implementation, inspired by @jonas054's answer.This uses a pattern similar to Delegator. This way you don't have to list all the methods you want to delegate, since it will delegate all...

View Article

Answer by Ramon de C Valle for How can I have ruby logger log output to...

You can also add multiple device logging functionality directly into the Logger:require 'logger'class Logger # Creates or opens a secondary log file. def attach(name) @logdev.attach(name) end # Closes...

View Article
Browsing all 23 articles
Browse latest View live




Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>
<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596344.js" async> </script>