1. We need logging to tell us what's happening in our code 2. Python has an inbuilt logging module which can be imported 3. DEBUG, INFO, WARNING, ERROR & CRITICAL are the level of logging available. 4. WARNING is the default logging level #100DaysOfCode
Having a config file with all components of the logging file is ideal.
It offers:
>> Single point to configure logs, their handlers & their format
>> Ability for non-coders to change the log formats
Day 7:
Since Python 3.2 the config file format has been moved to a YAML which we will see in the coming days
Day 8: A dive into various log handlers which with the help of 1. Have a format in which the log is displayed 2. The level of logs to be displayed decide where the log is written
✅StreamHandler >> Writes to the console
✅FileHandler >> Writes to a file on the disk
are the most common types of handlers used.
Below code snippet shows usage of both.
>> Error logs & above are written to a file
>> All logs are written to the console
>> the logging.debug(), info(), etc signature shows a **kwargs parameter.
It can take in 3 arguments
1⃣ exc_info to display traceback data
2⃣ stack_info to display traceback data
3⃣ extra to display use custom formatter attribute
Since Python 3.8 there is a 4th argument available
4⃣ stacklevel which defaults to 1. If greater than 1, the corresponding number of stack frames are skipped when computing the line number and function name set in the LogRecord created for the logging event
Day 11:
Looking to add more information to your logs like traceback ? Here is how we can do it.
> Python logs are largely meant for humans but sometimes we may need to pass it to log analytics platforms as SPLUNK, Logstash, etc. These platforms consume data in JSON format
> We can use the python-json-logger module to output logs in JSON format
Day 16: LoggerAdapter for adding more info to logs
>> The logging module comes with a number of formatters but often you might need to pass additional context info to the logs & display it. This can be done using the LoggerAdapter class
2⃣ Specify an additional attribute in the formatter
3⃣ We then pass the logger from step #1 & contextual info to LoggerAdapter class
4⃣ The info(), error() & other methods are then called on instance of LoggerAdapter
Day17:
>> We can override the process method in the LoggerAdapter class pass contextual/additional information with each log
>> Overriding the process method gives us the ability to pass a unique contextual info with each log
Day 18: Filtering Python Logs
>> Filters allow you to
> Reject records based on certain criteria
> Add custom info to logs
>> We need to override the logging.Filter & then attach it to handler using .addFilter()
Day 19 Of Python Logging: Filtering
>> Yesterday we saw how we can add filters to logs to prevent certain logs from showing up
>> But what if you need to log to show up but just a part of the log message to be hidden ? Just pass the LogRecord.msg to a new function to do the job
Day 20 Of Python Logging:
>> Logging module is actually implemented in a thread-safe way.
>> Under the hood the logging module uses threading.RLock()
Day24: RotatingFileHandler() To Create Log Files Of Specified Size
✅ maxBytes controls the file size
✅ backCount controls the number of file of size maxBytes. Default is 0 meaning only 1 file
✅ filename attribute is the filename
>> Rotate log files after certain time interval
>> Rotated files are automatically appended with a timestamp
>> Has a rich set of arguments to control the behaviour & output if the Handler.
Imagine you are working as a backend engineer for a company whose software is used by various retail outlets.
You've been tasked to create a class 'Product' which helps create a new product by taking in name, price & quantity_in_stock.
You do a simple harmless implementation ↓
Your firm now get's a new retail outlet who want to use your software but need to create the product not based on name, price & quantity_in_stock but a product_code
• What is an API Gateway?
• Why do we need to use API Gateway ?
• Visual Representation of API Gateway
• How does an API Gateway work ?
• Functionalities offered by API Gateway
#1 What Is An API Gateway ?
• API Gateways are present at layer & of the OSI model & play an important part in distributed system design & microservice architecture
• It sits between clients & servers , acting as a reverse proxy & serving as a single entry point for all requests
• It simplifies the client-server interaction by also handling tasks such as authentication, request routing, rate limiting, SSL termination, request aggregation, validation & transformation
#2 Why do we need to use an API Gateway ?
• Clients code becomes complicated as number of services grow Backend service also need to individually handle authentication, SSL termination, validation, etc
• Single operation may require multiple services to work together, in such cases client-service communication becomes subject to more round trips & higher latency
• Hard coupling between clients & the backend. The clients need to know a lot of detail about each individual backend service and implement code accordingly
• What is a proxy ?
• Definition of reverse proxy
• Visual representation of reverse proxy
• Use cases of reverse proxy
• Load balancers vs reverse proxy
#1 What Is A Proxy ?
• A proxy in system architecture is an intermediary server that sits between a client and a target server
• It handles requests on behalf of the client, acting as a "middleman"
• Proxies can serve various functions, including improving security, balancing traffic loads, caching content, and hiding the client's IP address
• In simpler terms, it acts as a gateway between users and the web, either forwarding requests from clients to servers or handling incoming requests on behalf of servers
#2 Reverse Proxy ?
• A reverse proxy sits between clients and backend services
• Unlike a forward proxy (which handles requests from clients to external servers), a reverse proxy manages incoming requests from clients and routes them to the appropriate backend service
• It acts as a gateway for the server
• Imagine a website like Amazon or Netflix, which has millions of visitors. Instead of having all client requests directly hit their main servers, they use a reverse proxy (through a CDN) that routes requests to various servers across the globe
In my 11 years of working in tech I've had ZERO bad appraisals
Today let's try to understand corporate appraisals.
• What are appraisals ?
• How do they work ?
• Reviews & Ratings
• Increasing your odds of getting a better appraisal
!!! Disclaimer !!!
Appraisal processes vary from company to company & heavily linked with market conditions but the general framework used by most companies to give appraisals more or less remains the same & the points shared here are for knowledge sharing & not a framework
What are appraisals ?
• Corporate process where employee get a pay raise
• Raise is based on the review of yearly performance of individual, business unit the person works in & overall performance of company in general