# Logger's sync and flush returns NoMethod error

**URL:** <https://www.ruby-forum.com/t/loggers-sync-and-flush-returns-nomethod-error/191562>\
**Category:** Ruby\
**Created:** [July 14, 2010, 3:30pm UTC](https://www.ruby-forum.com/t/loggers-sync-and-flush-returns-nomethod-error/191562 "2010-07-14T15:30:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![RichardOnRails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e0b2c6/32.png) [@RichardOnRails](https://www.ruby-forum.com/u/RichardOnRails)\
**Post date:** [July 14, 2010, 3:30pm UTC](https://www.ruby-forum.com/t/loggers-sync-and-flush-returns-nomethod-error/191562/1 "2010-07-14T15:30:38Z")

</div>

Hi,

Below is my code, which works fine in Ruby 1.8.6 (with Rails 2.3.5),  
except that sync and flush both return NoMethod. Have thos methods  
been eliminated?

Thanks in Advance,  
Richard

equire ‘rubygems’  
require ‘active\_record’

class Account \< ActiveRecord::Base  
set\_table\_name “accounts”  
has\_many :comments  
end

class Comment \< ActiveRecord::Base  
set\_table\_name “comments”  
belongs\_to :account  
end

ActiveRecord::Base.establish\_connection(  
:adapter =\> ‘mysql’,  
:host =\> ‘localhost’,  
:database =\> ‘test’,  
:username =\> ‘root’,  
:password =\> “rlmrlm”)

mylog = Logger.new(‘mylog.txt’)

# mylog.sync = true # NoMethod

error  
ActiveRecord::Base.logger = mylog  
temp = Account.find(1)  
mylog.info(“Found a record with username: #{temp.username}” )  
mylog.info(‘About to show comments’)  
temp.comments.each do |rec|  
puts “#{temp.username} said #{rec.subject}”  
end  
#mylog.flush # NoMethod  
error

---

<div class="post-metadata">

**Author:** ![RichardOnRails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e0b2c6/32.png) [@RichardOnRails](https://www.ruby-forum.com/u/RichardOnRails)\
**Post date:** [July 14, 2010, 9:55pm UTC](https://www.ruby-forum.com/t/loggers-sync-and-flush-returns-nomethod-error/191562/2 "2010-07-14T21:55:56Z")

</div>

RichardOnRails wrote:

> Below is my code, which works fine in Ruby 1.8.6 (with Rails 2.3.5),  
> except that sync and flush both return NoMethod. Have thos methods  
> been eliminated?

sync= and flush are instance methods on IO objects. I don’t think Logger  
has them. Do you have anything which suggests that it does/did?

---

<div class="post-metadata">

**Author:** ![RichardOnRails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e0b2c6/32.png) [@RichardOnRails](https://www.ruby-forum.com/u/RichardOnRails)\
**Post date:** [July 16, 2010, 4:55am UTC](https://www.ruby-forum.com/t/loggers-sync-and-flush-returns-nomethod-error/191562/3 "2010-07-16T04:55:09Z")

</div>

Hi Brian,

> sync= and flush are instance methods on IO objects. I don’t think Logger  
> has them. Do you have anything which suggests that it does/did?

I found these on  
[http://maintainablesoftware.com/articles/rails\_logging\_tips](http://maintainablesoftware.com/articles/rails_logging_tips)

I was particularly interest in some flush capability the Logger seemed  
to truncate the last logged msg.

Thanks for responding.

Best wishes,  
Richard
