Skip to content

Reference for llmcode/utils/logger.py

This module configures logging for the application, ensuring compatibility across platforms.

It sets up a logging configuration with platform-specific adjustments, such as filtering out emojis on Windows systems to prevent display issues.

Functions: set_logging: Configures the logging settings for the application. emojis: Returns an emoji-safe version of a string based on the platform.

Classes: EmojiFilter: A custom logging filter class for removing emojis in log messages.

Author: Francisco Javier Gañán License File: https://github.com/javierganan99/LLMCode/blob/main/LICENSE


llmcode.utils.logger.EmojiFilter

Bases: Filter

A custom logging filter class for removing emojis in log messages.

This filter is particularly useful for ensuring compatibility with Windows terminals that may not support the display of emojis in log messages.

filter

filter(record)

Filter logs by emoji unicode characters on windows.

Source code in llmcode/utils/logger.py
63
64
65
66
def filter(self, record):
    """Filter logs by emoji unicode characters on windows."""
    record.msg = emojis(record.msg)
    return super().filter(record)





llmcode.utils.logger.set_logging

set_logging(name=LOGGING_NAME, verbose=True)
Source code in llmcode/utils/logger.py
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
def set_logging(name=LOGGING_NAME, verbose=True):
    # TODO: Document this function on your own. Could not be documented by the model.
    rank = int(os.getenv("RANK", -1))  # rank in world for Multi-GPU
    level = logging.INFO if verbose and rank in {-1, 0} else logging.ERROR
    logging.config.dictConfig(
        {
            "version": 1,
            "disable_existing_loggers": False,
            "formatters": {name: {"format": "%(message)s"}},
            "handlers": {
                name: {
                    "class": "logging.StreamHandler",
                    "formatter": name,
                    "level": level,
                }
            },
            "loggers": {name: {"level": level, "handlers": [name], "propagate": False}},
        }
    )





llmcode.utils.logger.emojis

emojis(string='')

Return platform-dependent emoji-safe version of string.

Source code in llmcode/utils/logger.py
50
51
52
def emojis(string=""):
    """Return platform-dependent emoji-safe version of string."""
    return string.encode().decode("ascii", "ignore") if WINDOWS else string