1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 # Services inserting a timestamp in all prints and to log each requests
16 # Also keep track of the performances of the requests
21 import performance_analysis
25 redef fun prepare_respond_and_close
(request
, truncated_uri
, http_server
) do
26 if not log_nitcorn_actions
then
31 print
"{http_server.remote_address}: {class_name} prepare for url:'{request.url}' body:'{request.body}' cookie:'{request.cookie.join(",", ":")}'"
37 var perf
= sys
.perfs
[class_name
]
39 if perf
.count
% perfs_print_period
== 0 then print
"{class_name} perfs: {perf}:"
43 redef class HttpServer
44 redef fun read_http_request
(str
)
46 print
"{remote_address}: received HTTP request"
50 redef fun respond
(response
)
53 if log_nitcorn_actions
then print
"{remote_address}: response header '{response.header.join(",", ":")}' to '{remote_address}'"
57 redef fun print
(object
) do
58 var timestamp
= new Tm.gmtime
59 super "{timestamp.year}/{timestamp.mon}/{timestamp.mday} "+
60 "{timestamp.hour}:{timestamp.min}:{timestamp.sec}: {object}"
63 redef fun print_error
(object
) do
64 var timestamp
= new Tm.gmtime
65 super "{timestamp.year}/{timestamp.mon}/{timestamp.mday} "+
66 "{timestamp.hour}:{timestamp.min}:{timestamp.sec}: {object}"
69 # Should the actions be logged? This may log sensitive data.
70 fun log_nitcorn_actions
: Bool do return false
72 # Number of actions executed before printing the perfs
73 fun perfs_print_period
: Int do return 20