Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
665 views
in Technique[技术] by (71.8m points)

object - how does logger work in a flask resource in python?

I'm building an API flask application, and i would like to get some logs. I'm using logging for this purpose, and it seems to work, but i don't understand how, and that's bothering me. First of all, i don't understand this part, regarding the logger :

api.add_resource(Login, '/login', resource_class_kwargs={'logger': logging.getLogger('login')})

The resource_class_kwargs will pass arguments ton my constructor for Object Login, ok, but what argument? a dict, with logger as key, but what is really the value of logging.getLogger('login') ?

in the class, i've define the logger in the constructor, but again, i don't really understand why, because, i don't understand what value will be pass to the constructor.

Last thing, what's the meaning of all that, at the end, i only use the output, with no reference to login (as specified in logging.getLogger)

self.logger.debug("username : %s ",username)

I'm uncomfortable with the copy/paste it's working i don't understand how and why technic, but i must say that it does the job from time to time.

If anyone can enlight me on this

question from:https://stackoverflow.com/questions/65951033/how-does-logger-work-in-a-flask-resource-in-python

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...