-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger.cpp
43 lines (39 loc) · 1.79 KB
/
logger.cpp
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
31
32
33
34
35
36
37
38
39
40
41
42
43
// ________ ____ __ __ __
// / ____/ /_ ____ _____ _______ __/ __ \____ / /_ __/ /_ ___ ____/ /________ _
// / / / __ \/ __ `/ __ \/ ___/ / / / /_/ / __ \/ / / / / __ \/ _ \/ __ / ___/ __ `/
// / /___/ / / / /_/ / / / / /__/ /_/ / ____/ /_/ / / /_/ / / / / __/ /_/ / / / /_/ /
// \____/_/ /_/\__,_/_/ /_/\___/\__, /_/ \____/_/\__, /_/ /_/\___/\__,_/_/ \__,_/
// /____/ /____/
//
// Copyright © 2017 D.E. Goodman-Wilson
//
#include "logger.hpp"
// Keep it simple for now
#include <iostream>
void error_logger(luna::log_level level, const std::string &message)
{
switch (level)
{
// case luna::log_level::DEBUG:
// std::cerr << "[ DEBUG] " << message << std::endl;
// break;
case luna::log_level::INFO:
std::cerr << "[ INFO] " << message << std::endl;;
break;
case luna::log_level::WARNING:
std::cerr << "[WARNING] " << message << std::endl;;
break;
case luna::log_level::ERROR:
std::cerr << "[ ERROR] " << message << std::endl;;
break;
case luna::log_level::FATAL:
std::cerr << "[ FATAL] " << message << std::endl;;
break;
}
}
void access_logger(const luna::request &request, const luna::response &response)
{
std::cout << request.ip_address << ": " << luna::to_string(request.method) << " [" << response.status_code << "] "
<< request.path << " " << request.http_version << " " << (request.headers.count("user-agent") ? request.headers.at("user-agent") : "[no user-agent]") << " { "
<< std::chrono::duration_cast<std::chrono::microseconds>(request.end - request.start).count() << "us } " << std::endl;
}