-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathLogger.pm
More file actions
30 lines (23 loc) · 820 Bytes
/
Logger.pm
File metadata and controls
30 lines (23 loc) · 820 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package WeBWorK3::Controller::Logger;
use warnings;
use strict;
use Mojo::Base 'Mojolicious::Controller', -signatures;
use Mojo::Home;
use Mojo::Log;
use JSON qw/decode_json/;
my $clientLogFile = Mojo::Log->new(path => Mojo::Home->new->detect('WeBWorK3')->child('logs', 'clientLog.log'));
sub clientLog ($c) {
my $rawJSON = $c->req->body;
my $logEntry = decode_json($rawJSON);
my $level = ($logEntry->{level} =~ /(debug|info|warn|error)/) ? $1 : 'fatal';
# Optionally log information from user cookie...
for my $cookie (@{ $c->req->cookies }) {
$c->log->info($cookie->to_string);
}
# Write entire json to file in production mode
$clientLogFile->$level($rawJSON); # if ($ENV{MOJO_MODE} && $ENV{MOJO_MODE} eq 'production');
$c->log->$level($logEntry->{message});
$c->rendered(200);
return;
}
1;