Lines 2-11
package Koha::REST::V1;
Link Here
|
2 |
|
2 |
|
3 |
use Modern::Perl; |
3 |
use Modern::Perl; |
4 |
use Mojo::Base 'Mojolicious'; |
4 |
use Mojo::Base 'Mojolicious'; |
|
|
5 |
use Mojo::Log; |
6 |
|
7 |
=head startup |
8 |
|
9 |
Starts the Mojolicious application using whatever server is configured. |
10 |
|
11 |
Use environmental values to control some aspects of Mojolicious: |
12 |
This way we can have different settings for different servers running Mojolicious. |
13 |
|
14 |
=head2 Configuration file |
15 |
|
16 |
$ENV{MOJO_CONFIG} should be set in the system service (init) starting Mojolicious, eg: |
17 |
export MOJO_CONFIG=/home/koha/kohaclone/api/v1/hypnotoad.conf |
18 |
|
19 |
This configuration file read by the Mojolicious::Plugin::Config |
20 |
http://mojolicio.us/perldoc/Mojolicious/Plugin/Config |
21 |
|
22 |
=head2 Logging |
23 |
|
24 |
#NOTE!! |
25 |
#There is a "feature" in Mojo::Server disabling STDOUT and STDERR, because such errors are not-suited-for-production?!? |
26 |
#This modification in Mojo::Server disables this and preserves the STD* handles for forked server threads |
27 |
#in Mojo::Server::daemonize(), comment out the following lines |
28 |
# |
29 |
# # Close filehandles |
30 |
# open STDOUT, '>/dev/null'; |
31 |
# open STDERR, '>&STDOUT'; |
32 |
|
33 |
Log to a filename configured in an environment variable $ENV{MOJO_LOGFILES} using loglevel $ENV{MOJO_LOGLEVEL}. |
34 |
Actually you get 3 logfiles on $ENV{MOJO_LOGFILES}. |
35 |
.log for Mojo::Log |
36 |
.stdout for STDOUT |
37 |
.stderr for STDERR |
38 |
|
39 |
Defaults to STDERR and loglevel of 'error' |
40 |
Examples: |
41 |
export MOJO_LOGFILES=/home/koha/koha-dev/var/log/kohaapi.mojo |
42 |
export MOJO_LOGLEVEL=debug |
43 |
|
44 |
Logging is done by Mojo::Log |
45 |
http://www.mojolicio.us/perldoc/Mojo/Log |
46 |
|
47 |
=cut |
5 |
|
48 |
|
6 |
sub startup { |
49 |
sub startup { |
7 |
my $self = shift; |
50 |
my $self = shift; |
8 |
|
51 |
|
|
|
52 |
#Log to a filename with loglevel configured in environment variables |
53 |
if ($ENV{MOJO_LOGFILES}) { |
54 |
$self->app->log( Mojo::Log->new( path => $ENV{MOJO_LOGFILES}.'.log', level => ($ENV{MOJO_LOGLEVEL} || 'error') ) ); |
55 |
open(STDOUT,'>>',$ENV{MOJO_LOGFILES}.'.stdout') or die __PACKAGE__."::startup():> Couldn't open the STDOUT logfile for appending.\n".$!; |
56 |
open(STDERR,'>>',$ENV{MOJO_LOGFILES}.'.stderr') or die __PACKAGE__."::startup():> Couldn't open the STDERR logfile for appending.\n".$!; |
57 |
} |
58 |
else { |
59 |
$self->app->log(); #Default to STDERR |
60 |
print __PACKAGE__."::startup():> No logfile given, defaulting to STDERR. Define your logfile and loglevel to the MOJO_LOGFILE and MOJO_LOGLEVEL environmental variables.\n"; |
61 |
} |
62 |
|
63 |
#Enable the config-plugin. Loads the config file from $ENV{MOJO_CONFIG} by default. |
64 |
if ($ENV{MOJO_CONFIG}) { |
65 |
$self->plugin('Config'); |
66 |
} |
67 |
else { |
68 |
print __PACKAGE__."::startup():> No config-file loaded. Define your config-file to the MOJO_CONFIG environmental variable.\n"; |
69 |
} |
70 |
|
9 |
my $route = $self->routes->under->to( |
71 |
my $route = $self->routes->under->to( |
10 |
cb => sub { |
72 |
cb => sub { |
11 |
my $c = shift; |
73 |
my $c = shift; |
12 |
- |
|
|