PageRenderTime 49ms CodeModel.GetById 47ms app.highlight 0ms RepoModel.GetById 1ms app.codeStats 1ms

/dozer/templates/logbar.mako

https://bitbucket.org/bbangert/dozer/
Mako | 131 lines | 128 code | 3 blank | 0 comment | 5 complexity | d16fe74c801f095e152894d8ba6a294f MD5 | raw file
  1<%!
  2import time
  3converter = time.localtime
  4def format_time(record, start, prev_record=None):
  5    if prev_record:
  6        delta_from_prev = (record.created - prev_record.created) * 1000
  7        return '%+dms' % delta_from_prev
  8    else:
  9        time_from_start = (record.created - start) * 1000
 10        return '%+dms' % time_from_start
 11
 12def bg_color(event, log_colors):
 13    if event.name in log_colors:
 14        return log_colors[event.name]
 15    for key in log_colors:
 16        if event.name.startswith(key):
 17            return log_colors[key]
 18    return '#fff'
 19
 20def fg_color(frame, traceback_colors):
 21    for key in traceback_colors:
 22        if key in frame:
 23            return traceback_colors[key]
 24    return None
 25%>
 26
 27<div style="width: 100%; position: absolute; top:0; left: 0; z-index: 200000; font-size:11px;">
 28    <div style="width: 100%; background-color: #fff; border: 1px solid #999; padding: 3px; cursor: pointer;" onclick="javascript:DLV.show_events('DLVlogevents');">\
 29        View log events for this request
 30    </div>
 31<div id="DLVlogevents" style="display:none;">
 32    <table style="width: 100%; overflow: auto; background-color: #ddd;padding:2px;">
 33        <thead>
 34            <tr>
 35                <th>Time</th>
 36                <th>Level</th>
 37                <th>Module</th>
 38                <th>Message</th>
 39            </tr>
 40        </thead>
 41        <tbody>
 42        <% prev_event = None %>
 43        % for event in events:
 44        <% bgcolor = bg_color(event, logcolors) %>
 45            <tr style="text-align: left; vertical-align: top; border-bottom: 1px solid #333; background-color: ${bgcolor}; color: #222;">
 46                <td style="background-color: ${bgcolor}; text-align: right;">${format_time(event, start, prev_event)}</td>
 47                <td style="background-color: ${bgcolor};">${event.levelname}</td>
 48                <td style="background-color: ${bgcolor};">${event.name}</td>
 49                <td style="background-color: ${bgcolor};">\
 50                    <% 
 51                        msg = event.getMessage()
 52                        length_limit = 130
 53                        keep_last = 70
 54                        if len(msg) > length_limit:
 55                            use_split = True
 56                            first = msg[:length_limit - keep_last]
 57                            middle = msg[length_limit - keep_last:-keep_last]
 58                            last = msg[-keep_last:]
 59                        else:
 60                            use_split = False
 61                    %>
 62                    % if use_split:
 63                        <span style="cursor: pointer; text-decoration: underline;" onclick="javascript:DLV.show_span(${id(event)})">${first}</span>\
 64<span style="display:inline;" id="${id(event)}_extra"> ... </span><span id="${id(event)}" style="display:none">${middle}</span>${last}
 65                    % else:
 66                        ${msg | h}\
 67                    % endif
 68                    % if hasattr(event, 'traceback'):
 69                    <span style="float: right; cursor: pointer; text-decoration: underline;" onclick="javascript:DLV.show_block('${'tb%s' % id(event)}')">TB</span>
 70                    <pre id="${'tb%s' % id(event)}" style="display: none; padding-top: 1em">
 71                        % for frame in event.traceback:
 72<% fgcolor = fg_color(frame, traceback_colors) %>\
 73                            % if fgcolor:
 74<span style="color: ${fgcolor}">${frame}</span>\
 75                            % else:
 76${frame}\
 77                            % endif
 78                        % endfor
 79</pre>
 80                    % endif
 81                </td>
 82            </tr>
 83        <% prev_event = event %>
 84        % endfor
 85        <tr style="text-align: left; vertical-align: top; border-bottom: 1px solid #333; background-color: #eee; color: #222;">
 86            <th colspan="2">Total Time:</th>
 87            <td colspan="4">${'%d' % (1000*tottime)}ms</td>
 88        </tr>
 89        </tbody>
 90    </table>
 91</div>
 92</div>
 93<script>
 94var DLV = {};
 95DLV.getEBI = function(id, d) {
 96    return (d || document).getElementById(id);
 97};
 98DLV.show_events = function(name) {
 99    var elem = DLV.getEBI(name);
100    if (elem.style.display == 'block') {
101        elem.style.display = 'none';
102    } else {
103        elem.style.display = 'block';
104    }
105    return false;
106};
107DLV.show_span = function(name) {
108    var elem = DLV.getEBI(name);
109    if (elem.style.display == 'inline') {
110        elem.style.display = 'none';
111    } else {
112        elem.style.display = 'inline';
113    }
114    elem = DLV.getEBI(name+'_extra');
115    if (elem.style.display == 'inline') {
116        elem.style.display = 'none';
117    } else {
118        elem.style.display = 'inline';
119    }
120    return false;
121};
122DLV.show_block = function(name) {
123    var elem = DLV.getEBI(name);
124    if (elem.style.display == 'block') {
125        elem.style.display = 'none';
126    } else {
127        elem.style.display = 'block';
128    }
129    return false;
130};
131</script>