예제 #1
0
def print_wrapper(prefix: str, level: int, file_path: str,
                  message: str) -> bool:
    """Prints a line to the file_path with the prefix only if the logging level
	of the warcraft package is more than this level.

	:param file_path: The path to the file to print too.
	:type file_path: str
	:param message: The message to print to the file.
	:type message: str
	:param logging_level: The current logging level, use purpose is to override
	current status.
	:type logging_level: int

	:return: Whether the print to file was successful.
	:rtype: bool
	"""
    try:
        if level <= logging_level.cvar.get_int():
            with open(file_path, "a") as file_obj:
                file_obj.write(prefix + message + "\n")
            engine_server.log_print(prefix + message + "\n")
        return True
    except:
        engine_server.log_print(f"Failed to log to {file_path}!\n")
        return False
예제 #2
0
    def _log(self, level, msg, *args, dump=False, **kwargs):
        """Main logging method."""
        # Does the message need logged?
        if self.level > level:

            # If not, simply return
            return

        # Get the areas to be used
        areas = self.areas

        # Print to main log file?
        if MAIN_LOG & areas:

            # Import engine_server
            # This is done here to fix an ImportError
            from engines.server import engine_server

            # Is a prefix supposed to be logged?
            if not dump:

                # Create the record
                record = self.logger.makeRecord(
                    self.logger.name, level,
                    '(unknown file)', 0, msg, args, None)

                # Get the message to send
                message = _main_log_formatter.format(record)

            # Is the message not supposed to have a prefix?
            else:

                # Use the given message
                message = msg

            # Print to the main log
            engine_server.log_print(message + '\n')

        # Print to the console?
        if CONSOLE & areas and not dump:

            # If not, print to the console
            # If <engine>.log_print is called with logging being on,
            #   the console is already echoed with the message.
            from core import echo_console
            echo_console(msg)

        # Print to the script's log file?
        if SCRIPT_LOG & areas and self.root != _sp_logger:

            # Print message to the log file
            self.logger.log(level, msg, *args, **kwargs)

        # Print to the main SP log file?
        if SP_LOG & areas:

            # Print to the SP log file
            _sp_logger.logger.log(level, msg, *args, **kwargs)
예제 #3
0
    def _log(self, level, msg, *args, **kwargs):
        """Main logging method."""
        # Does the message need logged?
        if self.level > level:

            # If not, simply return
            return

        # Get the areas to be used
        areas = self.areas

        # Print to main log file?
        if MAIN_LOG & areas:

            # Import engine_server
            # This is done here to fix an ImportError
            from engines.server import engine_server

            # Create the record
            record = self.logger.makeRecord(
                self.logger.name, level,
                '(unknown file)', 0, msg, args, None)

            # Get the message to send
            message = _main_log_formatter.format(record)

            # Print to the main log
            engine_server.log_print(message + '\n')

        # Print to the console?
        if CONSOLE & areas:

            # If not, print to the console
            # If <engine>.log_print is called with logging being on,
            #   the console is already echoed with the message.
            from core import echo_console
            echo_console(msg)

        # Print to the script's log file?
        if SCRIPT_LOG & areas and self.root != _sp_logger:

            # Print message to the log file
            self.logger.log(level, msg, *args, **kwargs)

        # Print to the main SP log file?
        if SP_LOG & areas:

            # Print to the SP log file
            _sp_logger.logger.log(level, msg, *args, **kwargs)
예제 #4
0
def logq(argv):
  engine_server.log_print(' '.join(argv) + '\n')
예제 #5
0
def eventscripts_log(command):
    engine_server.log_print(PLUGIN_VERSION_DESCRIPTION)
    engine_server.log_print('\n')
예제 #6
0
def logq(argv):
    engine_server.log_print(' '.join(argv) + '\n')
    def _log(self, level, msg, *args, **kwargs):
        """Main logging method."""
        # Does the message need logged?
        if self.level > level:

            # If not, simply return
            return

        # Get the areas to be used
        areas = self.areas

        # Get wether we should prepend prefix
        prepend_prefix = kwargs.pop('prepend_prefix', self.prefix is not None)

        # Print to main log file?
        if MAIN_LOG & areas:

            # Import engine_server
            # This is done here to fix an ImportError
            from engines.server import engine_server

            # Create the record
            record = self.logger.makeRecord(self.logger.name, level,
                                            '(unknown file)', 0, msg, args,
                                            None)

            # Get the message to send
            message = _main_log_formatter.format(record)

            # Prepend prefix
            if prepend_prefix:
                message = self.prefix + message

            # Print to the main log
            engine_server.log_print(message + '\n')

        # Print to the console?
        if CONSOLE & areas:

            # If not, print to the console
            # If <engine>.log_print is called with logging being on,
            #   the console is already echoed with the message.
            from core import echo_console

            # Prepend prefix
            if prepend_prefix:
                msg = self.prefix + msg

            echo_console(msg)

        # Print to the script's log file?
        if SCRIPT_LOG & areas and self.root != _sp_logger:

            # Print message to the log file
            self.logger.log(level, msg, *args, **kwargs)

        # Print to the main SP log file?
        if SP_LOG & areas:

            # Get the given extra dictionary
            extra = kwargs.setdefault('extra', dict())

            # Set the logger name
            extra.setdefault('logger_name', self.logger.name)

            # Print to the SP log file
            _sp_logger.logger.log(level, msg, *args, **kwargs)