[logging] added webnotes.log() and logging property in conf.py to enable debug logs
This commit is contained in:
parent
096b9a179c
commit
bbefbfb35b
3 changed files with 29 additions and 10 deletions
|
|
@ -151,8 +151,8 @@ wn.request.cleanup = function(opts, r) {
|
|||
}
|
||||
|
||||
// show messages
|
||||
if(r.server_messages) {
|
||||
r.server_messages = JSON.parse(r.server_messages)
|
||||
if(r._server_messages) {
|
||||
r._server_messages = JSON.parse(r._server_messages)
|
||||
msgprint(r.server_messages);
|
||||
}
|
||||
|
||||
|
|
@ -164,10 +164,15 @@ wn.request.cleanup = function(opts, r) {
|
|||
if(v)console.log(v);
|
||||
})
|
||||
} else {
|
||||
console.log(r.exc);
|
||||
console.log(r.exc);
|
||||
}
|
||||
};
|
||||
|
||||
// debug messages
|
||||
if(r._debug_messages) {
|
||||
$.each(JSON.parse(r._debug_messages), function(i, v) { console.log(v); });
|
||||
}
|
||||
|
||||
if(r['403']) {
|
||||
wn.set_route('403');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -68,6 +68,7 @@ incoming_cookies = {}
|
|||
add_cookies = {} # append these to outgoing request
|
||||
cookies = {}
|
||||
response = _dict({'message':'', 'exc':''})
|
||||
error_log = []
|
||||
debug_log = []
|
||||
message_log = []
|
||||
mute_emails = False
|
||||
|
|
@ -105,7 +106,16 @@ def errprint(msg):
|
|||
print repr(msg)
|
||||
|
||||
from utils import cstr
|
||||
debug_log.append(cstr(msg or ''))
|
||||
error_log.append(repr(msg))
|
||||
|
||||
def log(msg):
|
||||
if not request_method:
|
||||
import conf
|
||||
if getattr(conf, "logging", False):
|
||||
print repr(msg)
|
||||
|
||||
from utils import cstr
|
||||
debug_log.append(cstr(msg))
|
||||
|
||||
def msgprint(msg, small=0, raise_exception=0, as_table=False):
|
||||
from utils import cstr
|
||||
|
|
|
|||
|
|
@ -213,6 +213,7 @@ def get_method(cmd):
|
|||
method = webnotes.get_method(cmd)
|
||||
else:
|
||||
method = globals()[cmd]
|
||||
webnotes.log("method:" + cmd)
|
||||
return method
|
||||
|
||||
def print_response():
|
||||
|
|
@ -257,7 +258,7 @@ def print_iframe():
|
|||
eprint("")
|
||||
eprint(webnotes.response.get('result') or '')
|
||||
|
||||
if webnotes.debug_log:
|
||||
if webnotes.error_log:
|
||||
import json
|
||||
eprint("""\
|
||||
<script>
|
||||
|
|
@ -275,7 +276,7 @@ def print_iframe():
|
|||
}
|
||||
</script>""" % {
|
||||
'messages': json.dumps(webnotes.message_log).replace("'", "\\'"),
|
||||
'errors': json.dumps(webnotes.debug_log).replace("'", "\\'"),
|
||||
'errors': json.dumps(webnotes.error_log).replace("'", "\\'"),
|
||||
})
|
||||
|
||||
def print_raw():
|
||||
|
|
@ -289,13 +290,16 @@ def print_raw():
|
|||
|
||||
def make_logs():
|
||||
"""make strings for msgprint and errprint"""
|
||||
import json
|
||||
import json, conf
|
||||
from webnotes.utils import cstr
|
||||
if webnotes.debug_log:
|
||||
webnotes.response['exc'] = json.dumps("\n".join([cstr(d) for d in webnotes.debug_log]))
|
||||
if webnotes.error_log:
|
||||
webnotes.response['exc'] = json.dumps("\n".join([cstr(d) for d in webnotes.error_log]))
|
||||
|
||||
if webnotes.message_log:
|
||||
webnotes.response['server_messages'] = json.dumps([cstr(d) for d in webnotes.message_log])
|
||||
webnotes.response['_server_messages'] = json.dumps([cstr(d) for d in webnotes.message_log])
|
||||
|
||||
if webnotes.debug_log and getattr(conf, "logging", False):
|
||||
webnotes.response['_debug_messages'] = json.dumps(webnotes.debug_log)
|
||||
|
||||
def print_cookie_header():
|
||||
"""if there ar additional cookies defined during the request, add them"""
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue