[4236] | 1 | #---------------------------------- logging plugin -------------------------------# |
---|
| 2 | |
---|
| 3 | cdef to_str(ptrlen, char[] ptr, start=0): |
---|
| 4 | return str(bytes([ ptr[i+start*ptrlen] for i in range(ptrlen)]), encoding='utf8').rstrip() |
---|
| 5 | |
---|
| 6 | """ |
---|
| 7 | SUBROUTINE default_flush_plugin(lev, taglen, tag, buflen, bufsize, buf) |
---|
| 8 | INTEGER(c_int), INTENT(IN), VALUE :: lev, taglen, buflen, bufsize |
---|
| 9 | CHARACTER(KIND=c_char), INTENT(IN) :: tag(taglen), buf(buflen, bufsize) |
---|
| 10 | """ |
---|
| 11 | |
---|
| 12 | cdef flush_plugin_wrap(int lev, int taglen, char[] tag, int buflen, int bufsize, char[] buf): |
---|
| 13 | flush_plugin(to_str(taglen, tag), [to_str(buflen, buf, i) for i in range(bufsize) ] ) |
---|
| 14 | |
---|
| 15 | def default_flush_plugin(tag, buf): |
---|
| 16 | if tag != 'missing_plugin' : |
---|
| 17 | n = len(buf) |
---|
| 18 | for i,line in enumerate(buf): |
---|
| 19 | print( '[%s %2.2d/%2.2d] %s'%(tag, i+1, n, line) ) |
---|
| 20 | |
---|
| 21 | def set_flush(plugin): |
---|
| 22 | flush_plugin = plugin |
---|
| 23 | |
---|
| 24 | #----------------------------- plug plugins in ----------------------------------# |
---|
| 25 | |
---|
| 26 | flush_plugin = default_flush_plugin |
---|
| 27 | |
---|
| 28 | phy.phyparam_set_plugins_logging(&flush_plugin_wrap) |
---|