mirror of
https://github.com/xcat2/confluent.git
synced 2025-01-17 13:13:18 +00:00
Add one-call tracing to log-as-a-file
When a log object is used as a 'dumb' file target, show the origin of the output. The motivation here is that 'print' statements are intended to be an unusual event that should be easily tracked down and eliminated once their specific use has concluded. In xcatd, running '-f' means a lot of mysterious output that is hard to manage as they frequently print out variable contents without searchable context. For example, if in xcatd someone randomply prints out a varibale with a nodename, we might see a stray: n1 With this change (together with previous changes), the same statement results in stdout log appearing like: Jan 19 14:20:54 File "/opt/confluent/lib/python/confluent/plugins/hardwaremanagement/ipmi.py", line 364, in _dict_sensor print nodename: n1
This commit is contained in:
parent
8bc6477700
commit
6acaac8644
@ -1,6 +1,7 @@
|
||||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
||||
|
||||
# Copyright 2014 IBM Corporation
|
||||
# Copyright 2015 Lenovo
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
@ -66,6 +67,7 @@ import json
|
||||
import os
|
||||
import struct
|
||||
import time
|
||||
import traceback
|
||||
|
||||
# on conserving filehandles:
|
||||
# upon write, if file not open, open it for append
|
||||
@ -235,7 +237,7 @@ class Logger(object):
|
||||
:param data: data to log
|
||||
"""
|
||||
if data != '\n': # 'print' likes to do '\n' by itself, skip that
|
||||
self.log(data)
|
||||
self.log(traceback.format_stack(limit=2)[0][:-1] + ": " + data)
|
||||
|
||||
def flush(self):
|
||||
pass
|
||||
|
Loading…
x
Reference in New Issue
Block a user