webmcp

view framework/env/trace/_render_sub_tree.lua @ 29:0b7e87f2dc91

add trace.debug_traceback() function

It inserts a traceback into the trace debug log. Usefull on development of unknown code.
author Daniel Poelzleithner <poelzi@poelzi.org>
date Mon Sep 20 15:29:23 2010 +0200 (2010-09-20)
parents 9fdfb27f8e67
children 1cd9e69b85cb
line source
1 local function open(class)
2 slot.put('<li class="trace_' .. class .. '">')
3 end
4 local function open_head()
5 slot.put('<div class="trace_head">')
6 end
7 local function close_head()
8 slot.put('</div>')
9 end
10 local function close()
11 slot.put('</li>')
12 end
13 function trace._render_sub_tree(node)
14 local function render_children(tail)
15 if #node > 0 then
16 slot.put('<ul class="trace_list">')
17 for idx, child in ipairs(node) do
18 trace._render_sub_tree(child)
19 end
20 if tail then
21 slot.put(tail)
22 end
23 slot.put("</ul>")
24 end
25 end
26 local function close_with_children()
27 close_head()
28 render_children()
29 close()
30 end
31 local node_type = node.type
32 if node_type == "root" then
33 render_children()
34 elseif node_type == "debug" then
35 open("debug")
36 slot.put(encode.html(node.message))
37 close()
38 elseif node_type == "traceback" then
39 open("debug")
40 slot.put('<pre>')
41 slot.put(encode.html(node.message))
42 slot.put('</pre>')
43 close()
44 elseif node_type == "request" then
45 open("request")
46 open_head()
47 slot.put("REQUESTED")
48 if node.view then
49 slot.put(" VIEW")
50 elseif node.action then
51 slot.put(" ACTION")
52 end
53 slot.put(
54 ": ",
55 encode.html(node.module),
56 "/",
57 encode.html(node.view or node.action)
58 )
59 close_with_children()
60 elseif node_type == "config" then
61 open("config")
62 open_head()
63 slot.put('Configuration "', encode.html(node.name), '"')
64 close_with_children()
65 elseif node_type == "filter" then
66 open("filter")
67 open_head()
68 slot.put(encode.html(node.path))
69 close_with_children()
70 elseif node_type == "view" then
71 open("view")
72 open_head()
73 slot.put(
74 "EXECUTE VIEW: ",
75 encode.html(node.module),
76 "/",
77 encode.html(node.view)
78 )
79 close_with_children()
80 elseif node_type == "action" then
81 if
82 node.status and (
83 node.status == "ok" or
84 string.find(node.status, "^ok_")
85 )
86 then
87 open("action_success")
88 elseif
89 node.status and (
90 node.status == "error" or
91 string.find(node.status, "^error_")
92 )
93 then
94 open("action_softfail")
95 else
96 open("action_neutral")
97 end
98 open_head()
99 slot.put(
100 "EXECUTE ACTION: ",
101 encode.html(node.module),
102 "/",
103 encode.html(node.action)
104 )
105 close_head()
106 if node.status == "softfail" then
107 render_children(
108 '<li class="trace_action_status">Status code: "' ..
109 encode.html(node.failure_code) ..
110 '"</li>'
111 )
112 else
113 render_children()
114 end
115 close()
116 elseif node_type == "redirect" then
117 open("redirect")
118 open_head()
119 slot.put("303 REDIRECT TO VIEW: ", encode.html(node.module), "/", encode.html(node.view))
120 close_with_children()
121 elseif node_type == "forward" then
122 open("forward")
123 open_head()
124 slot.put("INTERNAL FORWARD TO VIEW: ", encode.html(node.module), "/", encode.html(node.view))
125 close_with_children()
126 elseif node_type == "exectime" then
127 open("exectime")
128 open_head()
129 slot.put(
130 "Finished after " ..
131 string.format("%.1f", os.monotonic_hires_time() * 1000) ..
132 ' ms (' ..
133 string.format("%.1f", os.clock() * 1000) ..
134 ' ms CPU)'
135 )
136 close_with_children()
137 elseif node_type == "sql" then
138 open("sql")
139 if node.error_position then
140 -- error position starts counting with 1
141 local part1 = string.sub(node.command, 1, node.error_position - 1)
142 --local part2 = string.sub(node.command, node.error_position - 1, node.error_position + 1)
143 local part2 = string.sub(node.command, node.error_position)
144 slot.put(encode.html(part1))
145 slot.put('<span class="trace_error_position">&rArr;</span>')
146 slot.put(encode.html(part2))
147 --slot.put('</span>')
148 --slot.put(encode.html(part3))
149 else
150 slot.put(encode.html(node.command))
151 end
152 close();
153 elseif node_type == "error" then
154 open("error")
155 open_head()
156 slot.put("UNEXPECTED ERROR")
157 close_head()
158 close()
159 end
160 end

Impressum / About Us