Also keep track of the performances of the requests
HttpRequest
class and services to create it
Serializable::inspect
to show more useful information
more_collections :: more_collections
Highly specific, but useful, collections-related classes.serialization :: serialization_core
Abstract services to serialize Nit objects to different formatscore :: union_find
union–find algorithm using an efficient disjoint-set data structureperformance_analysis :: performance_analysis
Services to gather information on the performance of events by categories
# Services inserting a timestamp in all prints and to log each requests
# Also keep track of the performances of the requests
module log
import reactor
import realtime
import performance_analysis
redef class Action
redef fun prepare_respond_and_close(request, truncated_uri, http_server) do
if not log_nitcorn_actions then
super
return
end
print "{http_server.remote_address}: {class_name} prepare for url:'{request.url}' body:'{request.body}' cookie:'{request.cookie.join(",", ":")}'"
var clock = new Clock
super
var perf = sys.perfs[class_name]
perf.add(clock.lapse)
if perf.count % perfs_print_period == 0 then print "{class_name} perfs: {perf}:"
end
end
redef class HttpServer
redef fun read_http_request(str)
do
print "{remote_address}: received HTTP request"
super
end
redef fun respond(response)
do
super
if log_nitcorn_actions then print "{remote_address}: response header '{response.header.join(",", ":")}' to '{remote_address}'"
end
end
redef fun print(object) do
var timestamp = new Tm.gmtime
super "{timestamp.year}/{timestamp.mon}/{timestamp.mday} "+
"{timestamp.hour}:{timestamp.min}:{timestamp.sec}: {object}"
end
redef fun print_error(object) do
var timestamp = new Tm.gmtime
super "{timestamp.year}/{timestamp.mon}/{timestamp.mday} "+
"{timestamp.hour}:{timestamp.min}:{timestamp.sec}: {object}"
end
# Should the actions be logged? This may log sensitive data.
fun log_nitcorn_actions: Bool do return false
# Number of actions executed before printing the perfs
fun perfs_print_period: Int do return 20
lib/nitcorn/log.nit:15,1--73,40