diff --git a/README.md b/README.md index b3960ee..5f96e3e 100644 --- a/README.md +++ b/README.md @@ -2449,46 +2449,54 @@ if __name__ == '__main__': Logging ------- + ```python -# $ pip3 install loguru -from loguru import logger +import logging ``` ```python -logger.add('debug_{time}.log', colorize=True) # Connects a log file. -logger.add('error_{time}.log', level='ERROR') # Another file for errors or higher. -logger.('A logging message.') # Logs to file/s and prints to stderr. +logging.basicConfig(filename=) # Configures the root logger. +logging.debug/info/warning/error/critical() # Logs to the root logger. + = logging.getLogger(__name__) # Creates a logger named after the module. +.() # All messages propagate to the root logger. +.exception() # Appends caught exception and calls error(). ``` -* **Levels: `'debug'`, `'info'`, `'success'`, `'warning'`, `'error'`, `'critical'`.** - -### Exceptions -**Exception description, stack trace and values of variables are appended automatically.** +### Setup ```python -try: - ... -except : - logger.exception('An error happened.') +logging.basicConfig( + filename=None, # Logs to console by default. + format='%(levelname)s:%(name)s:%(message)s', # Add `%(asctime)s` for datetime. + level=logging.WARNING, # Drops messages with lower priority. + handlers=[logging.StreamHandler()] # [FileHandler(filename)] if filename is set. +) ``` -### Rotation -**Argument that sets a condition when a new log file is created.** ```python -rotation=||| + = logging.Formatter('') # Creates a Formatter. + = logging.FileHandler() # Creates a Handler. +.setFormatter() # Adds Formatter to the Handler. +.setLevel() # Processes all messages by default. +.addHandler() # Adds Handler to the Logger. +.setLevel() # What is sent to handlers and parents. ``` -* **`''` - Max file size in bytes.** -* **`''` - Max age of a file.** -* **`'