Skip to content

Commit

Permalink
improve commands and log messages to use less punctuation
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Jan 26, 2015
1 parent d25c31d commit 748a2e1
Show file tree
Hide file tree
Showing 50 changed files with 255 additions and 257 deletions.
1 change: 1 addition & 0 deletions Changes
Expand Up @@ -5,6 +5,7 @@
failed.
- Improved Hypnotoad to wait for new workers to be ready before stopping the
old ones during hot deployment.
- Improved commands and log messages to use less punctuation.
- Fixed race condition and memory leak in Mojo::Server::Prefork.

5.74 2015-01-25
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -54,7 +54,7 @@ app->start;
code into a file and start it with `morbo`.

$ morbo hello.pl
Server available at http://127.0.0.1:3000.
Server available at http://127.0.0.1:3000

$ curl http://127.0.0.1:3000/
I ♥ Mojolicious!
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo.pm
Expand Up @@ -87,7 +87,7 @@ which stringifies to the actual path.
The logging layer of your application, defaults to a L<Mojo::Log> object.
# Log debug message
$app->log->debug('It works!');
$app->log->debug('It works');
=head2 ua
Expand Down
36 changes: 18 additions & 18 deletions lib/Mojo/Log.pm
Expand Up @@ -94,11 +94,11 @@ Mojo::Log - Simple logger
my $log = Mojo::Log->new(path => '/var/log/mojo.log', level => 'warn');
# Log messages
$log->debug('Why is this not working?');
$log->info('FYI: it happened again.');
$log->warn('This might be a problem.');
$log->error('Garden variety error.');
$log->fatal('Boom!');
$log->debug('Not sure what is happening here');
$log->info('FYI: it happened again');
$log->warn('This might be a problem');
$log->error('Garden variety error');
$log->fatal('Boom');
=head1 DESCRIPTION
Expand Down Expand Up @@ -137,7 +137,7 @@ A callback for formatting log messages.
$log->format(sub {
my ($time, $level, @lines) = @_;
return "[Thu May 15 17:47:04 2014] [info] I ♥ Mojolicious.\n";
return "[Thu May 15 17:47:04 2014] [info] I ♥ Mojolicious\n";
});
=head2 handle
Expand All @@ -151,7 +151,7 @@ L</"path"> or C<STDERR>.
=head2 history
my $history = $log->history;
$log = $log->history([[time, 'debug', 'That went wrong.']]);
$log = $log->history([[time, 'debug', 'That went wrong']]);
The last few logged messages.
Expand Down Expand Up @@ -186,35 +186,35 @@ the following new ones.
=head2 append
$log->append("[Thu May 15 17:47:04 2014] [info] I ♥ Mojolicious.\n");
$log->append("[Thu May 15 17:47:04 2014] [info] I ♥ Mojolicious\n");
Append message to L</"handle">.
=head2 debug
$log = $log->debug('You screwed up, but that is ok.');
$log = $log->debug('All', 'cool!');
$log = $log->debug('You screwed up, but that is ok');
$log = $log->debug('All', 'cool');
Log debug message.
=head2 error
$log = $log->error('You really screwed up this time.');
$log = $log->error('Wow', 'seriously!');
$log = $log->error('You really screwed up this time');
$log = $log->error('Wow', 'seriously');
Log error message.
=head2 fatal
$log = $log->fatal('Its over...');
$log = $log->fatal('Bye', 'bye!');
$log = $log->fatal('Bye', 'bye');
Log fatal message.
=head2 info
$log = $log->info('You are bad, but you prolly know already.');
$log = $log->info('Ok', 'then!');
$log = $log->info('You are bad, but you prolly know already');
$log = $log->info('Ok', 'then');
Log info message.
Expand Down Expand Up @@ -256,8 +256,8 @@ Check for warn log level.
=head2 log
$log = $log->log(debug => 'This should work.');
$log = $log->log(debug => 'This', 'too!');
$log = $log->log(debug => 'This should work');
$log = $log->log(debug => 'This', 'too');
Emit L</"message"> event.
Expand All @@ -271,7 +271,7 @@ default logger.
=head2 warn
$log = $log->warn('Dont do that Dave...');
$log = $log->warn('No', 'really!');
$log = $log->warn('No', 'really');
Log warn message.
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/Server.pm
Expand Up @@ -92,7 +92,7 @@ sub setuidgid {
return $self;
}

sub _error { $_[0]->app->log->error("$_[1].") and croak $_[1] }
sub _error { $_[0]->app->log->error($_[1]) and croak $_[1] }

1;

Expand Down
6 changes: 3 additions & 3 deletions lib/Mojo/Server/Daemon.pm
Expand Up @@ -166,15 +166,15 @@ sub _listen {
sub { $self && $self->app->log->error(pop) && $self->_close($id) });
$stream->on(read => sub { $self->_read($id => pop) });
$stream->on(timeout =>
sub { $self->app->log->debug('Inactivity timeout.') if $c->{tx} });
sub { $self->app->log->debug('Inactivity timeout') if $c->{tx} });
}
);

return if $self->silent;
$self->app->log->info(qq{Listening at "$url".});
$self->app->log->info(qq{Listening at "$url"});
$query->params([]);
$url->host('127.0.0.1') if $url->host eq '*';
say "Server available at $url.";
say "Server available at $url";
}

sub _read {
Expand Down
7 changes: 3 additions & 4 deletions lib/Mojo/Server/Hypnotoad.pm
Expand Up @@ -98,7 +98,7 @@ sub _manage {
my $log = $prefork->app->log;
if ($ENV{HYPNOTOAD_PID} && $ENV{HYPNOTOAD_PID} ne $$) {
return unless $prefork->healthy == $prefork->workers;
$log->info("Upgrade successful, stopping $ENV{HYPNOTOAD_PID}.");
$log->info("Upgrade successful, stopping $ENV{HYPNOTOAD_PID}");
kill 'QUIT', $ENV{HYPNOTOAD_PID};
}
$ENV{HYPNOTOAD_PID} = $$ unless ($ENV{HYPNOTOAD_PID} // '') eq $$;
Expand All @@ -108,7 +108,7 @@ sub _manage {

# Fresh start
unless ($self->{new}) {
$log->info('Starting zero downtime software upgrade.');
$log->info('Starting zero downtime software upgrade');
die "Can't fork: $!" unless defined(my $pid = $self->{new} = fork);
exec $^X, $ENV{HYPNOTOAD_EXE} or die "Can't exec: $!" unless $pid;
}
Expand All @@ -124,7 +124,7 @@ sub _reap {

# Clean up failed upgrade
return unless ($self->{new} || '') eq $pid;
$self->prefork->app->log->error('Zero downtime software upgrade failed.');
$self->prefork->app->log->error('Zero downtime software upgrade failed');
delete @$self{qw(new upgrade)};
}

Expand Down Expand Up @@ -164,7 +164,6 @@ automatically daemonizes the server process and defaults to C<production> mode
for L<Mojolicious> and L<Mojolicious::Lite> applications.
$ hypnotoad ./myapp.pl
Server available at http://127.0.0.1:8080.
You can run the same command again for automatic hot deployment.
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/Server/Morbo.pm
Expand Up @@ -127,7 +127,7 @@ applications.
To start applications with it you can use the L<morbo> script.
$ morbo ./myapp.pl
Server available at http://127.0.0.1:3000.
Server available at http://127.0.0.1:3000
For better scalability (epoll, kqueue) and to provide non-blocking name
resolution, SOCKS5 as well as TLS support, the optional modules L<EV> (4.0+),
Expand Down
14 changes: 7 additions & 7 deletions lib/Mojo/Server/Prefork.pm
Expand Up @@ -51,7 +51,7 @@ sub ensure_pid_file {
return if -e (my $file = $self->pid_file);

# Create PID file
$self->app->log->info(qq{Creating process id file "$file".});
$self->app->log->info(qq{Creating process id file "$file"});
die qq{Can't create process id file "$file": $!}
unless open my $handle, '>', $file;
chmod 0644, $handle;
Expand Down Expand Up @@ -83,7 +83,7 @@ sub run {
local $SIG{CHLD} = sub {
while ((my $pid = waitpid -1, WNOHANG) > 0) {
next unless my $w = delete $self->emit(reap => $pid)->{pool}{$pid};
$self->app->log->debug("Worker $pid stopped.");
$self->app->log->debug("Worker $pid stopped");
$self->{finished} = 1 unless $w->{healthy};
}
};
Expand All @@ -96,7 +96,7 @@ sub run {
};

# Preload application before starting workers
$self->start->app->log->info("Manager $$ started.");
$self->start->app->log->info("Manager $$ started");
$self->{running} = 1;
$self->_manage while $self->{running};
}
Expand Down Expand Up @@ -128,19 +128,19 @@ sub _manage {
next unless my $w = $self->{pool}{$pid};

# No heartbeat (graceful stop)
$log->error("Worker $pid has no heartbeat, restarting.")
$log->error("Worker $pid has no heartbeat, restarting")
and $w->{graceful} = $time
if !$w->{graceful} && ($w->{time} + $interval + $ht <= $time);

# Graceful stop with timeout
my $graceful = $w->{graceful} ||= $self->{graceful} ? $time : undef;
$log->debug("Trying to stop worker $pid gracefully.")
$log->debug("Trying to stop worker $pid gracefully")
and (kill('QUIT', $pid) or delete $self->{pool}{$pid})
if $graceful && !$w->{quit}++;
$w->{force} = 1 if $graceful && $graceful + $gt <= $time;

# Normal stop
$log->debug("Stopping worker $pid.")
$log->debug("Stopping worker $pid")
and (kill('KILL', $pid) or delete $self->{pool}{$pid})
if $w->{force} || ($self->{finished} && !$graceful);
}
Expand Down Expand Up @@ -194,7 +194,7 @@ sub _spawn {
$SIG{QUIT} = sub { $loop->max_connections(0) };
delete @$self{qw(poll reader)};

$self->app->log->debug("Worker $$ started.");
$self->app->log->debug("Worker $$ started");
$loop->start;
exit 0;
}
Expand Down
8 changes: 4 additions & 4 deletions lib/Mojolicious.pm
Expand Up @@ -32,7 +32,7 @@ has secrets => sub {
my $self = shift;

# Warn developers about insecure default
$self->log->debug('Your secret passphrase needs to be changed!!!');
$self->log->debug('Your secret passphrase needs to be changed');

# Default to moniker
return [$self->moniker];
Expand Down Expand Up @@ -102,7 +102,7 @@ sub dispatch {
my $req = $c->req;
my $method = $req->method;
my $path = $req->url->path->to_abs_string;
$self->log->debug(qq{$method "$path".});
$self->log->debug(qq{$method "$path"});
$stash->{'mojo.started'} = [Time::HiRes::gettimeofday];
}

Expand All @@ -127,14 +127,14 @@ sub handler {
$self->plugins->emit_chain(around_dispatch => $c);

# Delayed response
$self->log->debug('Nothing has been rendered, expecting delayed response.')
$self->log->debug('Nothing has been rendered, expecting delayed response')
unless $c->tx->is_writing;
}

sub helper {
my ($self, $name, $cb) = @_;
my $r = $self->renderer;
$self->log->debug(qq{Helper "$name" already exists, replacing.})
$self->log->debug(qq{Helper "$name" already exists, replacing})
if exists $r->helpers->{$name};
$r->add_helper($name => $cb);
}
Expand Down
10 changes: 5 additions & 5 deletions lib/Mojolicious/Command.pm
Expand Up @@ -13,7 +13,7 @@ use Mojo::Util qw(spurt unindent);
use Pod::Usage 'pod2usage';

has app => sub { Mojo::Server->new->build_app('Mojo::HelloWorld') };
has description => 'No description.';
has description => 'No description';
has 'quiet';
has usage => "Usage: APPLICATION\n";

Expand Down Expand Up @@ -99,14 +99,14 @@ Mojolicious::Command - Command base class
use Mojo::Base 'Mojolicious::Command';
# Short description
has description => 'My first Mojo command.';
has description => 'My first Mojo command';
# Short usage message
has usage => <<EOF;
Usage: APPLICATION mycommand [OPTIONS]
Options:
-s, --something Does something.
-s, --something Does something
EOF
sub run {
Expand Down Expand Up @@ -139,7 +139,7 @@ Application for command, defaults to a L<Mojo::HelloWorld> object.
=head2 description
my $description = $command->description;
$command = $command->description('Foo!');
$command = $command->description('Foo');
Short description of command, used for the command list.
Expand All @@ -153,7 +153,7 @@ Limited command output.
=head2 usage
my $usage = $command->usage;
$command = $command->usage('Foo!');
$command = $command->usage('Foo');
Usage information for command, used for the help screen.
Expand Down
8 changes: 4 additions & 4 deletions lib/Mojolicious/Command/cgi.pm
Expand Up @@ -4,7 +4,7 @@ use Mojo::Base 'Mojolicious::Command';
use Getopt::Long qw(GetOptionsFromArray :config no_auto_abbrev no_ignore_case);
use Mojo::Server::CGI;

has description => 'Start application with CGI.';
has description => 'Start application with CGI';
has usage => sub { shift->extract_usage };

sub run {
Expand All @@ -26,7 +26,7 @@ Mojolicious::Command::cgi - CGI command
Usage: APPLICATION cgi [OPTIONS]
Options:
--nph Enable non-parsed-header mode.
--nph Enable non-parsed-header mode
=head1 DESCRIPTION
Expand All @@ -47,14 +47,14 @@ L<Mojolicious::Command> and implements the following new ones.
=head2 description
my $description = $cgi->description;
$cgi = $cgi->description('Foo!');
$cgi = $cgi->description('Foo');
Short description of this command, used for the command list.
=head2 usage
my $usage = $cgi->usage;
$cgi = $cgi->usage('Foo!');
$cgi = $cgi->usage('Foo');
Usage information for this command, used for the help screen.
Expand Down

0 comments on commit 748a2e1

Please sign in to comment.