I am looking for a design pattern for logging from within library code. Suppose I have a function in a library file that i expect will be used by multiple front-ends (lets assume a CLI and a web):
def foo(a,b): log("Processing a") p(a) log("Processing b") p(b)
Where would the foo get the "log" from? Should it:
- Have an optional argument logger which supplies the object which implements log?
- Consult a logger repository of sort - e.g
- Always be part of an object (no static/class methods i.o.w) and the object be initialized with a logger as per (1)?
Let's assume we're talking about a language with built in logging framework such as Python or a framework which is often used such as log4j in Java.