Understanding and Practical Experience with Python's Logging Library

This article starts with the basic concepts of the Python logging library to understand its execution flow and some details that might be overlooked. Log Levels The logging library has 5 preset error levels, plus a NOTSET level, which is the default value for a logger. CRITICAL = 50 ERROR = 40 WARNING = 30 INFO = 20 DEBUG = 10 NOTSET = 0 The logging library also supports custom error levels. As seen in the source code above, there are 10 numeric positions reserved between different error levels, allowing us to add more detailed error levels on top of the preset ones. ...

January 25, 2019 · 7 min · Zhiya

Pitfalls Encountered in Go JSON Practice

During the development process using the Go language, the json package is often used for mutual conversion between JSON and structs. In the process, I encountered some areas that require extra attention, which I have documented below. Integer to Float Conversion Issue Suppose there is a Person structure that contains two fields: Age int64 and Weight float64. Now, let’s convert the Person structure to map[string]interface{} using the json package. The code is as follows: ...

December 24, 2018 · 5 min · Zhiya

User Authentication Practice Based on JWT + Refresh Token

HTTP is a stateless protocol, meaning once a request is completed, the server doesn’t know who sent the next request (the same IP doesn’t represent the same user). In web applications, user authentication and authorization are crucial, and there are multiple practical solutions, each with its own merits. Session-Based Session Management In the early development of web applications, most adopted session-based session management, which works as follows: ...

December 13, 2018 · 6 min · Zhiya

SSH Tunneling Through ngrok

ngrok To access a host using SSH, if you are on the same local network as the host or if the host has a public IP, you can connect directly using the SSH command with the host’s IP address. However, most companies and homes use local networks and cannot assign a public IP to each host within the network. In such cases, network tunneling is needed to connect to hosts within a local network from the outside. ...

December 10, 2018 · 2 min · Zhiya

Unicode and UTF-8

The concepts of Unicode and UTF-8 are fundamental and important, yet they are often overlooked. Character Set In computer systems, all data is stored in binary, and all operations are represented in binary. Human languages and symbols also need to be converted into binary form to be stored in computers, which necessitates a mapping table from human language to binary encoding. This mapping table is called a character set. ...

December 7, 2018 · 3 min · Zhiya