Closed ankitbko closed 3 years ago
A preview build of this branch has been generated for SHA: b11d09dac9b446171926f2b885578ce7bfc99122 and can be viewed live at: https://60735c480da39327febe0d63--nifty-hoover-140256.netlify.app
The current fastpages site built from master can be viewed for comparison here
/preview
A preview build of this branch has been generated for SHA: f684c0c1a13744818b70d40ef10856347471db9b and can be viewed live at: https://60735eea9984304721f58afa--nifty-hoover-140256.netlify.app
The current fastpages site built from master can be viewed for comparison here
/preview
A preview build of this branch has been generated for SHA: 9b29374dc443227de8149e0351c9d46f86a117b4 and can be viewed live at: https://60736049ed3fb5298ded605d--nifty-hoover-140256.netlify.app
The current fastpages site built from master can be viewed for comparison here
/preview
A preview build of this branch has been generated for SHA: dba05b377216188c7f8cc3b6dddbd298077bad2f and can be viewed live at: https://60736261a170ca4a9cc1b9e2--nifty-hoover-140256.netlify.app
The current fastpages site built from master can be viewed for comparison here
diff --git a/_posts/2021-04-15-logging-in-python.md b/_posts/2021-04-15-logging-in-python.md
index 461e86d..55e0dd5 100644
--- a/_posts/2021-04-15-logging-in-python.md
+++ b/_posts/2021-04-15-logging-in-python.md
@@ -31,7 +31,7 @@ def sum(a, b=10):
('a', 'b')
-Since functions behave like any other object, you could assign sum
to another function. Then calling sum
will call this another function instead of the one that we defined before. The decorators utilizes this behavior by assigning sum
a new function which takes sum
as parameter and wraps some additional logic around it thereby extending it without modifying the function itself.
+Since functions behave like any other object, you could assign sum
to another function. Then calling sum
will call this other function instead of the one that we defined before. The decorators utilizes this behavior by assigning sum
a new function which takes sum
as parameter and wraps some additional logic around it thereby extending it without modifying the function itself.
@@ -99,7 +99,7 @@ Traceback (most recent call last):
Exception: Something went wrong
-In addition to setting up the logger
, we have also used @functools.wraps decorator. The wraps
decorator updates the wrapper
function to look like func
. Our @log
decorator can now be used on any function to catch every exception from wrapped function and log it in consistent manner.
+In addition to setting up the logger
, we have also used @functools.wraps decorator. The wraps
decorator updates the wrapper
function to look like func
. Our @log
decorator can now be used on any function to catch every exception from wrapped function and log it in a consistent manner.
Since wrapper
function accepts all arguments (*args and **kwargs
), the @log
decorator can be extended to capture all the parameters passed to the decorated function. We can do this by just iterating over args and kwargs and joining them to form string message to log.
@@ -135,7 +135,7 @@ This basic logging decorator looks good and already does what we originally set
However in real projects, the logger
can itself be abstracted away into its own class that initializes a logger based on certain configuration (such as push log to a cloud sink). In this case its useless to log into console by creating our own logger in the @log
decorator. We need a way to pass an existing logger
into our decorator at runtime. To do this we can extend the @log
decorator to accept logger
as an argument.
-To mimic this scenario we will start with having a class that returns us creates logger for us. For now we will create the basic logger but you can imagine the class configuring the behavior of the logger as required. +To mimic this scenario we will start with having a class that creates a creates logger for us. For now we will create the basic logger but you can imagine the class configuring the behavior of the logger as required.
class MyLogger:
/preview
/preview
/preview
A preview build of this branch has been generated for SHA: bf5769addc1f42575a7be150d6f7df01b577f79b and can be viewed live at: https://6077bbb73ccd3a5841360e41--nifty-hoover-140256.netlify.app
The current fastpages site built from master can be viewed for comparison here
/preview