Giter Site home page Giter Site logo

alertua / global_logger Goto Github PK

View Code? Open in Web Editor NEW
3.0 3.0 0.0 6.23 MB

Based on Python built-in logger, expands it, and provides a global logger to your system.

Home Page: https://pypi.org/project/global-logger/

License: MIT License

Makefile 7.59% Python 92.41%
logging logging-library python2 python3

global_logger's Introduction

Stand With Ukraine Made in Ukraine Stand With Ukraine Russian Warship Go Fuck Yourself

Projects

Contributions

Archived Projects

global_logger's People

Contributors

alertua avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

global_logger's Issues

allow log_session_filename to be set

  • Global Logger version: global-logger==0.3.26
  • Python version: 3.9.7 64 bit
  • Operating System: Windows 10

Description

There doesn't seem to be a way to change the log file name. This is possible by setting the log_session_filename

What I Did

**global-logger.py**
    # pylint: disable=too-many-locals,too-many-arguments,too-many-statements
    def __init__(self, name, level=None, global_level=True, logs_dir=None,  # noqa: C901
                 max_log_files=None, file_message_format=None, screen_message_format=None, date_format_full=None,
                 date_format=None, direct=True, log_session_filename=None):
        if direct:
            raise ValueError("You should create Global Logger via Log.get_logger() method.")

        level = level or Log.GLOBAL_LOG_LEVEL

        # pylint: disable=invalid-envvar-default
        verbose = os.getenv('LOG_VERBOSE', False)
        if global_level and verbose:
            level = Log.Levels.DEBUG

        self.name = name
        Log.log_session_filename = log_session_filename

       ----------------------------------------------------
       
                   if Log.log_session_filename is None:
                # pylint: disable=import-outside-toplevel
                from pendulum.tz.zoneinfo.exceptions import InvalidZoneinfoFile
                try:
                    now = pendulum.now()
                except InvalidZoneinfoFile:
                    now = pendulum.now(pendulum.UTC)  # travis-ci precaution
                Log.log_session_filename = "%s.log" % now.strftime('%Y-%m-%d_%H-%M-%S')
            else:
                Log.log_session_filename = str(log_session_filename + ".log")
            self._clean_logs_folder()



-------------------------------------------------------------------------------------------------------------------


    @classmethod
    def get_logger(cls, name=None, level=None, global_level=True, logs_dir=None, max_log_files=None, file_message_format=None, 
                   screen_message_format=None, date_format_full=None, date_format=None, log_session_filename=None):
        """
        Main instantiating method for the class. Use it to instantiate global logger.

        :param name: a unique logger name that is re-/used if already exists, defaults to the function path.
        :type name: str or unicode
        :param level: Logging level for the current instance.
        :type level: int
        :param global_level: Treat this level as a global (True) or as an individual (False)
                            Individual loggers do not gain global logging level changes.
        :type global_level: bool
        :param logs_dir: Path where the .log files would be created, if provided.
        :type logs_dir: Path or str or None
        :param max_log_files: Maximum .log files to store.
        :type max_log_files: int
        :param screen_message_format: Screen Logging message format.
        :type screen_message_format: str
        :param file_message_format: File Logging message format.
        :type file_message_format: str
        :param date_format_full: Logging full date format.
        :type date_format_full: str
        :param date_format: Logging on-screen date format.
        :type date_format: str
        :param log_session_filename: a unique log file name
        :type log_session_filename: str
        :return: :class:`Log` instance to work with.
        :rtype: :class:`Log`
        """
        name = name or get_prev_function_name()
        output = Log.loggers.get(name) or cls(name, level=level, global_level=global_level, logs_dir=logs_dir,
                                              max_log_files=max_log_files, file_message_format=file_message_format,
                                              screen_message_format=screen_message_format, date_format_full=date_format_full,
                                              date_format=date_format, direct=False, log_session_filename=log_session_filename)
        Log.loggers[name] = output
        Log._add_autoadded_handlers()
        return output

Can someone check in a fix for this?
Thanks!

Add log level to the console printouts

  • Global Logger version: 0.3.16
  • Python version: 3.9
  • Operating System: Windows 10

Add log level to the console printouts

Currently the console logs come without the the log level
Improvement: Add log level to the console printouts

My solution (I can do it but I think someone that already has the solution set up could do this much faster...):

In the global_logger.py
Update:
LOGGER_COLORED_MESSAGE_FORMAT = '%(log_color)s%(message)s'
to
LOGGER_COLORED_MESSAGE_FORMAT = '%(levelname)s: %(log_color)s%(message)s'

or ask user to pass a parameter that would allow them to customize the console logs as they wish or when setting the message_format apply that to the console log as well, similar to how we already do for the designated file logging.

logger_message_format = '%(asctime)s: %(filename)s:%(funcName)s: %(levelname)s: %(message)s'
log = Log.get_logger(message_format=logger_message_format)

Additionally, allow user to turn off console logging

Cheers!
Lily

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.