Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
664 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 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...