So I want to have the location of the log file be configurable.
And either I'm missing something basic or this is surprisingly painful.
I saw this discussion:

   https://github.com/kraih/mojo/issues/280

and it looks like the end result/consensus was that log configuration 
should live in the config file with all of the other application options 
(... not sure how this squares with the statement that server configuration 
and application configuration need to be separate; then again this was a 
decision made 4 years ago and it looks like people were generally happy 
with it, so I'm not sure if you'd want to change it now anyway...)

If log configuration info is in the config file then the first thing we 
have to do is read it:

    $self->plugin('Config');

but then:

(1) depending on what mode we're in, that much MAY already emit a log 
message -- currently it does in 'debug' mode to say what config file it's 
reading, otherwise not, but that behavior could change, never mind that 
config files themselves are executable and could theoretically do anything 
(even if they really shouldn't)

(2) once a log message has been emitted, it's non-trivial to redirect the 
log.   Setting log->path to a new value works as long as nothing has been 
logged yet, but otherwise the handle is open and changing log->path does 
nothing.

As things currently stand, I'm having to do this:

    # redirect log if specified in config
    if (my $log_path = $self->config->{log_path}) {
my $log = $self->log;
say "Logging at $log_path";
$log->debug("Log redirected to $log_path") if $log->{path};

# capture and close prior handle if necessary
my $prev_handle = delete $log->{handle};
close $prev_handle
  if $prev_handle && delete $log->{path};
  # i.e.,. handle was actually created and is *not* STDERR

$log->path($log_path);
$log->append($log->format->(@$_)) for @{$log->history};
    }

and you'll notice I'm relying WAY too much on the implementation of 
Mojo::Log.

I'm not certain what the Right Thing is here.
It's possible some or all of the above should be rolled into 
log->path(newpath)

(... One way out of the box that I'd explicitly reject would be an option 
to to suppress logging during Config plugin load, which seems like the 
Wrong Thing since if something happens during Config plugin load that 
somebody deemed worth logging about, I'd probably want to know about it. 
 At most you'd want to defer it but even then you're risking that the 
application will crash before anything gets written... the very situation 
you'd WANT something in a log file...)

-- 
You received this message because you are subscribed to the Google Groups 
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.

Reply via email to