Help & Guides
- Switching from Standard Logging to Loguru
- Introduction to logging in Python
- Fundamental differences between
logging
andloguru
- Replacing
getLogger()
function - Replacing
Logger
objects - Replacing
Handler
,Filter
andFormatter
objects - Replacing
LogRecord
objects - Replacing
%
style formatting of messages - Replacing
exc_info
argument - Replacing
extra
argument andLoggerAdapter
objects - Replacing
isEnabledFor()
method - Replacing
addLevelName()
andgetLevelName()
functions - Replacing
basicConfig()
anddictConfig()
functions - Replacing
captureWarnings()
function - Replacing
assertLogs()
method fromunittest
library - Replacing
caplog
fixture frompytest
library
- Frequently Asked Questions and Troubleshooting Tips for Loguru
- How do I create and configure a logger?
- Why are my logs duplicated in the output?
- How do I set the logging level?
- How do I customize the log format and re-use the default one?
- Why are my logs not colored?
- Why are my logs not appearing in the output?
- How can I use different loggers in different modules of my application?
- Why are my log files sometimes duplicated or the content trimmed?
- Why logging a message with f-string sometimes raises an exception?
- How do I fix “ValueError: I/O operation error on closed file”?
- How do I prevent “RuntimeError” due to “deadlock avoided”?
- Why is the source (name, file, function, line) of the log message incorrect or missing?
- Why can’t I access the
Logger
class and other types at runtime?
- Code Snippets and Recipes for Loguru
- Security considerations when using Loguru
- Avoiding logs to be printed twice on the terminal
- Changing the level of an existing handler
- Configuring Loguru to be used by a library or an application
- Sending and receiving log messages across network or processes
- Resolving
UnicodeEncodeError
and other encoding issues - Logging entry and exit of functions with a decorator
- Using logging function based on custom added levels
- Setting permissions on created log files
- Preserving an
opt()
parameter for the whole module - Serializing log messages using a custom function
- Rotating log file based on both size and time
- Adapting colors and format of logged messages dynamically
- Dynamically formatting messages to properly align values with padding
- Customizing the formatting of exceptions
- Displaying a stacktrace without using the error context
- Manipulating newline terminator to write multiple logs on the same line
- Capturing standard
stdout
,stderr
andwarnings
- Circumventing modules whose
__name__
value is absent - Interoperability with
tqdm
iterations - Using Loguru’s
logger
within a Cython module - Creating independent loggers with separate set of handlers
- Compatibility with
multiprocessing
usingenqueue
argument - Testing logging