Python Logger问题 - TypeError

时间:2014-11-26 15:21:39

标签: django

我在我的django应用程序中运行python脚本。

import logging,os,shelve

def logging_setup(app='default'):
    """ basic logging setup """
    logfile = '/var/log/folder/'+app+'.log'

    logger = logging.getLogger(app)
    hdlr = logging.FileHandler(logfile)
    formatter = logging.Formatter('%(asctime)s [%(levelname)s] %(message)s')
    hdlr.setFormatter(formatter)
    logger.addHandler(hdlr)
    logger.setLevel(logging.DEBUG)

    return loggerah man ive been slammed

然而,当我从我的代码中调用它时,我得到了..

    2014-11-26 15:24:56,977 [ERROR] 'ProcessAwareLogger' object is not callable
Traceback (most recent call last):
  File "/staging/nx/views.py", line 40, in nx_input
    crawl_data = nx_runner.main(device=serializer.data["input"])
  File "/staging/nx/runner.py", line 101, in main
    self.import_to_mongo()
  File "/staging/nx/runner.py", line 69, in import_to_mongo
    mongo_import.import_all_devices()
  File "/staging/nx/parser.py", line 194, in import_all_devices
    device_model = self.import_device(d)
  File "/staging/nx/parser.py", line 158, in import_device
    self.dstoreimport(str(aggrs))
TypeError: 'ProcessAwareLogger' object is not callable

我是通过......来调用的。

self.dstoreimport = logging_setup(app="dataImportMongo")
self.dstoreimport(str(aggrs))

任何想法......?

1 个答案:

答案 0 :(得分:4)

而不是

self.dstoreimport(str(aggrs))

self.dstoreimport.info(str(aggrs))

代替。

self.dstoreimport是一个记录器对象,因此不可调用(因此错误)。您需要调用该对象的实例方法(在此示例中,我使用info(),但您可以根据需要轻松调用debug()error()等代替