想知道是否有办法将实例的__repr__
转储到stderr而没有所有Apache的日志格式垃圾?
目前这是代码
def __repr__(self):
# instance's repr of the object
str = "<MyObj(\n"
for col in db_fields:
str += "%s = %s \n" % (col, self.get_db_col(col))
str += ")> \n"
return str
# main script
sys.stderr.write("%r", my_obj)
日志输出目前是:
[Mon Feb 09 10:28:02 2015] [error] [client 1.1.1.1] <MyObj(, referer: https://some.domain.com/
[Mon Feb 09 10:28:02 2015] [error] [client 1.1.1.1] db_field_1 = 1 , referer: https://some.domain.com/
[Mon Feb 09 10:28:02 2015] [error] [client 1.1.1.1] db_field_2 = False , referer: https://some.domain.com/
[Mon Feb 09 10:28:02 2015] [error] [client 1.1.1.1] db_field_3 = 'Descr' , referer: https://some.domain.com/
[Mon Feb 09 10:28:02 2015] [error] [client 1.1.1.1] )>
不可能阅读它,有没有办法在不触及Apache的conf的情况下以某种方式欺骗它?
我希望得到的结果是:
[Mon Feb 09 10:28:02 2015] [error] [client 1.1.1.1] <MyObj(, referer: https://some.domain.com/
db_field_1 = 1 , referer: https://some.domain.com/
db_field_2 = False , referer: https://some.domain.com/
db_field_3 = 'Descr' , referer: https://some.domain.com/
)>