mirror of
ssh://git.janware.com/srv/git/janware/proj/jw-python
synced 2026-01-15 09:53:32 +01:00
Implement caller keyword argument to slog()
Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
40e6add5ad
commit
860f7d8cab
2 changed files with 35 additions and 21 deletions
|
|
@ -72,7 +72,12 @@ def __pad(token, total_size, right_align = False):
|
|||
return space + token
|
||||
return token + space
|
||||
|
||||
def slog(prio, *args): # export
|
||||
def get_caller_pos(up = 1):
|
||||
assert(up == 1) # TODO: implement this
|
||||
caller_frame = inspect.currentframe().f_back.f_back
|
||||
return (basename(caller_frame.f_code.co_filename), caller_frame.f_lineno)
|
||||
|
||||
def slog(prio, *args, **kwargs): # export
|
||||
|
||||
if prio > level:
|
||||
return
|
||||
|
|
@ -86,10 +91,11 @@ def slog(prio, *args): # export
|
|||
msg += short_prio_str[prio] + ' '
|
||||
|
||||
if f_position in flags:
|
||||
caller_frame = inspect.currentframe().f_back
|
||||
line = '[' + __pad(str(caller_frame.f_lineno), 4, True) + ']'
|
||||
file = __pad(basename(caller_frame.f_code.co_filename), 20)
|
||||
msg += file + line
|
||||
if 'caller' in kwargs:
|
||||
name, line = kwargs['caller']
|
||||
else:
|
||||
name, line = get_caller_pos(1)
|
||||
msg += __pad(name, 20) + '[' + __pad(str(line), 4, True) + ']'
|
||||
|
||||
if f_color in flags:
|
||||
color_on, color_off = prio_colors[prio]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue