Build a logger that outputs to a file and to the console,
494923
def get_logger(name, namespace='{{project.package}}',
               log_level=DEFAULT_LOG_LEVEL, log_dir=DEFAULT_LOG_DIR):
    """"""

    log_level = (os.getenv('{}_LOG_LEVEL'.format(namespace.upper())) or
                 os.getenv('LOG_LEVEL', log_level))
    log_dir = (os.getenv('{}_LOG_DIR'.format(namespace.upper())) or
               os.getenv('LOG_DIR', log_dir))

    logger = logging.getLogger('{}.{}'.format(namespace, name))
    logger.setLevel(log_level)

    formatter = logging.Formatter(
        '%(asctime)s - %(name)s - %(levelname)s - %(message)s')

    # Create a console stream handler
    console_handler = logging.StreamHandler()
    console_handler.setLevel(log_level)
    console_handler.setFormatter(formatter)
    logger.addHandler(console_handler)

    try:
        if log_dir:
            log_path = os.path.abspath(log_dir)
            log_filename = '{name}.{pid}.log'.format(
                name=namespace, pid=os.getpid())

            file_path = str(os.path.join(log_path, log_filename))

            if not os.path.exists(log_path):
                os.makedirs(log_path, mode=774)

            # Create a file handler
            file_handler = logging.FileHandler(file_path)
            file_handler.setLevel(log_level)
            file_handler.setFormatter(formatter)
            logger.addHandler(file_handler)
    except OSError as e:
        logger.error('Could not create log file {file}: {error}'.format(
            file=file_path, error=e.strerror))

    return logger
901965
def log_to_file(self, message):
        """"""

        with self.build_fs.open(self.log_file, 'a+') as f:
            f.write(unicode(message + '\n'))
191650
def console_output(msg, logging_msg=None):
    """"""
    assert isinstance(msg, bytes)
    assert isinstance(logging_msg, bytes) or logging_msg is None

    from polysh import remote_dispatcher

    remote_dispatcher.log(logging_msg or msg)
    if remote_dispatcher.options.interactive:
        from polysh.stdin import the_stdin_thread
        the_stdin_thread.no_raw_input()
        global last_status_length
        if last_status_length:
            safe_write('\r{}\r'.format(
                last_status_length * ' ').encode())
            last_status_length = 0
    safe_write(msg)
451701
function print() {
    getLoggers().forEach(function (logger) {
        consoleAppender.log(formatText('Logger %b: %b, parent:%b', logger.name, logger.level, logger.parent));
    });
}
1267593
def _logger(self):
        
        log_level = {
            'debug': logging.DEBUG,
            'info': logging.INFO,
            'warning': logging.WARNING,
            'error': logging.ERROR,
            'critical': logging.CRITICAL,
        }
        level = log_level.get(self.args.logging_level.lower())

        # Formatter
        tx_format = '%(asctime)s - %(name)s - %(levelname)s - %(message)s '
        tx_format += '(%(funcName)s:%(lineno)d)'
        formatter = logging.Formatter(tx_format)

        # Logger
        log = logging.getLogger('tcrun')

        # # Stream Handler
        # sh = logging.StreamHandler()
        # sh.set_name('sh')
        # sh.setLevel(level)
        # sh.setFormatter(formatter)
        # log.addHandler(sh)

        # File Handler
        if not os.access('log', os.W_OK):
            os.makedirs('log')
        logfile = os.path.join('log', 'run.log')
        fh = logging.FileHandler(logfile)
        fh.set_name('fh')
        fh.setLevel(logging.DEBUG)
        fh.setFormatter(formatter)
        log.addHandler(fh)

        log.setLevel(level)
        log.info('Logging Level: {}'.format(logging.getLevelName(level)))
        return log
626439
def run_output(self):
        """"""
        for f in logdissect.output.__formats__:
            ouroutput = self.output_modules[f]
            ouroutput.write_output(self.data_set['finalized_data'],
                    args=self.args)
            del(ouroutput)

        # Output to terminal if silent mode is not set:
        if not self.args.silentmode:
            if self.args.verbosemode:
                print('\n==== ++++ ==== Output: ==== ++++ ====\n')
            for line in self.data_set['finalized_data']['entries']:
                print(line['raw_text'])
158509
def main():
    """"""
    formatter = ColoredFormatter(log_colors={'TRACE': 'yellow'})

    handler = logging.StreamHandler()
    handler.setFormatter(formatter)

    logger = logging.getLogger('example')
    logger.addHandler(handler)
    logger.setLevel('TRACE')

    logger.log(5, 'a message using a custom level')
167341
def log(program, message, exit_status = nil, files = nil)
      File.open(File.join(@log_directory, @log_file), "a") do |log|
        log.puts ""
        log.puts Time.now.to_s + " " + program
        log.puts message
        log.puts ""
      end

      if exit_status
        remove_files(files) unless files.nil?
        exit exit_status.to_i
      end
    end
213026
def main():
    """"""
    logger = setup_logger()

    logger.debug('a debug message')
    logger.info('an info message')
    logger.warning('a warning message')
    logger.error('an error message')
    logger.critical('a critical message')
113722
function (console) {

            var loggers = [
                {
                    name  : 'log',
                    color : 'white'
                },
                {
                    name  : 'info',
                    color : 'cyan'
                },
                {
                    name  : 'error',
                    color : 'red'
                },
                {
                    name  : 'warning',
                    color : 'yellow'
                },
                {
                    name  : 'dir',
                    color : 'white'
                }
            ];

            loggers.forEach(function (logger) {
                console.addLogger(logger.name, logger.color);
            });
        }
323806
def Logs(loggername, echo=True, debug=False, chatty=False, loglevel=logging.INFO, logfile=None, logpath=None, fileHandler=None):
    
    log = logging.getLogger(loggername)

    if fileHandler is None:
        if logfile is None:
            logFilename = _ourName
        else:
            logFilename = logfile

        if '.log' not in logFilename:
            logFilename = '%s.log' % logFilename

        if logpath is not None:
            logFilename = os.path.join(logpath, logFilename)

        _handler   = logging.FileHandler(logFilename)
        _formatter = logging.Formatter('%(asctime)s %(levelname)-7s %(message)s')

        _handler.setFormatter(_formatter)
        log.addHandler(_handler)
        # logging.fileHandler = _handler
    else:
        log.addHandler(fileHandler)
        # logging.fileHandler = fileHandler

    if echo:
        echoHandler = logging.StreamHandler()
        if chatty:
            echoFormatter = logging.Formatter('%(asctime)s %(levelname)-7s %(processName)s[%(process)d]: %(message)s')
        else:
            echoFormatter = logging.Formatter('%(asctime)s %(levelname)-7s %(message)s')
        echoHandler.setFormatter(echoFormatter)
        log.addHandler(echoHandler)

    if debug:
        log.setLevel(logging.DEBUG)
    else:
        log.setLevel(loglevel)

    atexit.register(shutdownLogging)
1219755
def write_to_logfile(logfile, out, err, cmd):
    
    with open(logfile, 'a+') as outfile:
        outfile.write('Command used: {}\n\n'.format(cmd))
        outfile.write('STDOUT: {}\n\n'.format(out))
        outfile.write('STDERR: {}\n\n'.format(err))
651852
def register_console_logging_handler(cls, lgr, level=logging.INFO):
        """"""
        console_handler = logger.DevassistantClHandler(sys.stdout)
        if console_handler.stream.isatty():
            console_handler.setFormatter(logger.DevassistantClColorFormatter())
        else:
            console_handler.setFormatter(logger.DevassistantClFormatter())
        console_handler.setLevel(level)
        cls.cur_handler = console_handler
        lgr.addHandler(console_handler)
45551
public function logger() : void
  {
    LogHandler::$disk = DEPConfig::$appdir . 'storage' . DIRECTORY_SEPARATOR . 'logs' . DIRECTORY_SEPARATOR;
    LogHandler::$name = config('app.logger.name');
    LogHandler::$log  = config('app.logger.log');
    LogHandler::$env  = config('app.env');

    LogHandler::event(function($env, $level, $message, $array) {
      Events::trigger('output.log', [$env, $level, $message, $array]);
    });
  }
570138
def log(self, msg, error=False):
        """"""
        output = self.stdout
        if error:
            output = self.stderr

        output.write(msg)
        output.write('\n')
468265
def _logger():
        """"""
        logger = logging.getLogger(__name__)
        logger.setLevel(logging.DEBUG)
        ch = logging.StreamHandler(sys.stdout)
        ch.setLevel(logging.DEBUG)
        logger.addHandler(ch)
        return logger
74377
def log_to_stream(stream=sys.stderr, level=logging.NOTSET,
                  fmt=logging.BASIC_FORMAT):
    
    fmt = Formatter(fmt)
    handler = StreamHandler()
    handler.setFormatter(fmt)
    handler.setLevel(level)

    log.addHandler(handler)