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 fun print
(object
) do
44 var timestamp
= new Tm.gmtime
45 super "{timestamp.year}/{timestamp.mon}/{timestamp.mday} "+
46 "{timestamp.hour}:{timestamp.min}:{timestamp.sec}: {object}"
49 redef fun print_error
(object
) do
50 var timestamp
= new Tm.gmtime
51 super "{timestamp.year}/{timestamp.mon}/{timestamp.mday} "+
52 "{timestamp.hour}:{timestamp.min}:{timestamp.sec}: {object}"
55 # Should the actions be logged? This may log sensitive data.
56 fun log_nitcorn_actions
: Bool do return false
58 # Number of actions executed before printing the perfs
59 fun perfs_print_period
: Int do return 20