Skip to content

Conversation

@srozum
Copy link

@srozum srozum commented Oct 12, 2016

Current initializer limit the usage of Syslogger. If I want to prepare logdev outside of method where Syslogger.new called I have to use this ::SysLogger::IO.new(&::SysLogger::Creators::unix_dgram_socket(ENV["LOG_DGRAM_SYSLOG"]))

super(SysLogger::IO.new(&block), shift_age, shift_size)
def initialize(logdev = nil, shift_age = 0, shift_size = 1048576)
if logdev.is_a?(Proc)
super(SysLogger::IO.new(logdev), shift_age, shift_size)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this actually work? I think it needs to be Syslogger::IO.new(&logdev). Anyways, I would rather just keep the syntax we have. Seems more standard to just accept a block that creates the logdev.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SysLogger::IO expects it to be a proc because it does .call by default.
& means that you passing proc as a block (last argument)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concur

module Creators
def self.unix_dgram_socket(socket_path)
proc {
Proc.new {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a no-op in the versions of ruby that this library supports (2+).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

want me to change it back?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really care. The source I looked at (http://batsov.com/articles/2014/02/04/the-elements-of-style-in-ruby-number-12-proc-vs-proc-dot-new/) says to prefer proc over Proc.new, but I only googled it for 3 seconds and don't know if that's the prevailing Ruby style elsewhere.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, look at this like raise which does Exception.new. You don't like it, right?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ha, he is talking about ruby 1.8 and 1.9... they are dead

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with raise FooException.new(arg1, arg2) just like I'm fine with proc { body }. But, like I said, I don't really care, I was just going off one style guide I looked at, since they're exactly identical constructs. I think the bigger issue is that I agree with @att14 that it's clearer to just pass a block using block-syntax rather than treating the first argument differently depending on its type, and I don't think the proc versus Proc.new difference is worth changing if it ends up being the only thing in this PR.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ruby style suggests duck typing over different combinations of arguments.
You are using MonoLogger, it means that I should be able to replace Syslogger with MonoLogger and don't have to change other code.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't get me wrong -- I think the entire logger interface in Ruby is braindead and awful. I would much prefer that we drop the arguments to initialize entirely and switch to something sane. It's a balancing act between having an interface which is vaguely similar to the existing (again, imo absolutely awful) interface and doing the right thing.

@srozum
Copy link
Author

srozum commented Oct 12, 2016

👎 ?

@att14 att14 removed their assignment Feb 12, 2021
@Justintime50
Copy link
Member

This still needed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants