Python logger.get() Examples
The following are 24
code examples of logger.get().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
logger
, or try the search function
.
Example #1
Source File: logger.py From revnet-public with MIT License | 6 votes |
def __init__(self, filename=None, default_verbose=0): """ Constructs a logger with optional log file output. Args: filename: optional log file output. If None, nothing will be written to file """ now = datetime.datetime.now() self.verbose_thresh = int(os.environ.get("VERBOSE", 0)) self.default_verbose = default_verbose if filename is not None: self.filename = filename dirname = os.path.dirname(self.filename) if not os.path.exists(dirname): os.makedirs(dirname) open(self.filename, "w").close() self.info("Log written to {}".format(os.path.abspath(self.filename))) else: self.filename = None pass
Example #2
Source File: logger.py From rec-attend-public with MIT License | 6 votes |
def __init__(self, filename=None, default_verbose=0): """ Constructs a logger with optional log file output. Args: filename: optional log file output. If None, nothing will be written to file """ now = datetime.datetime.now() self.verbose_thresh = int(os.environ.get("VERBOSE", 0)) self.default_verbose = default_verbose if filename is not None: self.filename = filename dirname = os.path.dirname(self.filename) if not os.path.exists(dirname): os.makedirs(dirname) open(self.filename, "w").close() self.info("Log written to {}".format(os.path.abspath(self.filename))) else: self.filename = None pass
Example #3
Source File: logger.py From meta-optim-public with MIT License | 6 votes |
def __init__(self, filename=None, default_verbose=0): """ Constructs a logger with optional log file output. Args: filename: optional log file output. If None, nothing will be written to file """ now = datetime.datetime.now() self.verbose_thresh = int(os.environ.get('VERBOSE', 0)) self.default_verbose = default_verbose if filename is not None: self.filename = filename dirname = os.path.dirname(self.filename) if not os.path.exists(dirname): os.makedirs(dirname) open(self.filename, 'w').close() self.info('Log written to {}'.format(os.path.abspath(self.filename))) else: self.filename = None pass
Example #4
Source File: logger.py From inc-few-shot-attractor-public with MIT License | 6 votes |
def __init__(self, filename=None, default_verbose=0): """ Constructs a logger with optional log file output. Args: filename: optional log file output. If None, nothing will be written to file """ now = datetime.datetime.now() self.verbose_thresh = int(os.environ.get("VERBOSE", 0)) self.default_verbose = default_verbose if filename is not None: self.filename = filename dirname = os.path.dirname(self.filename) if not os.path.exists(dirname): os.makedirs(dirname) open(self.filename, "w").close() self.info("Log written to {}".format(os.path.abspath(self.filename))) else: self.filename = None pass
Example #5
Source File: logger.py From tensorflow-forward-ad with MIT License | 6 votes |
def __init__(self, filename=None, default_verbose=0): """ Constructs a logger with optional log file output. Args: filename: optional log file output. If None, nothing will be written to file """ now = datetime.datetime.now() self.verbose_thresh = int(os.environ.get('VERBOSE', 0)) self.default_verbose = default_verbose if filename is not None: self.filename = filename dirname = os.path.dirname(self.filename) if not os.path.exists(dirname): os.makedirs(dirname) open(self.filename, 'w').close() self.info('Log written to {}'.format(os.path.abspath(self.filename))) else: self.filename = None pass
Example #6
Source File: logger.py From imageqa-qgen with MIT License | 6 votes |
def __init__(self, filename=None): """ Constructs a logger with optional log file output. Args: filename: optional log file output. If None, nothing will be written to file """ now = datetime.datetime.now() self.verbose_thresh = os.environ.get('VERBOSE', 0) if filename is not None: self.filename = \ '{}-{:04d}{:02d}{:02d}-{:02d}{:02d}{:02d}.log'.format( filename, now.year, now.month, now.day, now.hour, now.minute, now.second) dirname = os.path.dirname(self.filename) if not os.path.exists(dirname): os.makedirs(dirname) open(self.filename, 'w').close() self.info('Log written to {}'.format( os.path.abspath(self.filename))) else: self.filename = None pass
Example #7
Source File: logger.py From rec-attend-public with MIT License | 5 votes |
def get(fname=None): """ Returns a logger instance, with optional log file output. """ global log if log is not None and fname is None: return log # fname = os.environ.get("LOGTO", None) # if fname is None: # fname = default_fname else: log = Logger(fname) return log
Example #8
Source File: logger.py From revnet-public with MIT License | 5 votes |
def get(fname=None): """ Returns a logger instance, with optional log file output. """ global log if log is not None and fname is None: return log # fname = os.environ.get("LOGTO", None) # if fname is None: # fname = default_fname else: log = Logger(fname) return log
Example #9
Source File: logger.py From meta-optim-public with MIT License | 5 votes |
def get(fname=None): """ Returns a logger instance, with optional log file output. """ global log if log is not None and fname is None: return log # fname = os.environ.get('LOGTO', None) # if fname is None: # fname = default_fname else: log = Logger(fname) return log
Example #10
Source File: blescanmulti.py From bt-mqtt-gateway with MIT License | 5 votes |
def status_update(self): from bluepy import btle _LOGGER.info("Updating %d %s devices", len(self.devices), repr(self)) ret = [] try: devices = self.scanner.scan( float(self.scan_timeout), passive=booleanize(self.scan_passive) ) mac_addresses = {device.addr: device for device in devices} for status in self.last_status: device = mac_addresses.get(status.mac, None) status.set_status(device is not None) ret += status.generate_messages(device) except btle.BTLEException as e: logger.log_exception( _LOGGER, "Error during update (%s)", repr(self), type(e).__name__, suppress=True, ) return ret
Example #11
Source File: thermostat.py From bt-mqtt-gateway with MIT License | 5 votes |
def _setup(self): from eq3bt import Thermostat _LOGGER.info("Adding %d %s devices", len(self.devices), repr(self)) for name, obj in self.devices.items(): if isinstance(obj, str): self.devices[name] = {"mac": obj, "thermostat": Thermostat(obj)} elif isinstance(obj, dict): self.devices[name] = { "mac": obj["mac"], "thermostat": Thermostat(obj["mac"]), "discovery_temperature_topic": obj.get( "discovery_temperature_topic" ), "discovery_temperature_template": obj.get( "discovery_temperature_template" ), } else: raise TypeError("Unsupported configuration format") _LOGGER.debug( "Adding %s device '%s' (%s)", repr(self), name, self.devices[name]["mac"], )
Example #12
Source File: workers_manager.py From bt-mqtt-gateway with MIT License | 5 votes |
def _publish_config(self, mqtt): for command in self._config_commands: messages = command.execute() for msg in messages: msg.topic = "{}/{}".format( self._config["sensor_config"].get("topic", "homeassistant"), msg.topic, ) msg.retain = self._config["sensor_config"].get("retain", True) mqtt.publish(messages)
Example #13
Source File: workers_manager.py From bt-mqtt-gateway with MIT License | 5 votes |
def __init__(self, config): self._mqtt_callbacks = [] self._config_commands = [] self._update_commands = [] self._scheduler = BackgroundScheduler(timezone=utc) self._daemons = [] self._config = config self._command_timeout = config.get("command_timeout", DEFAULT_COMMAND_TIMEOUT)
Example #14
Source File: logger.py From imageqa-qgen with MIT License | 5 votes |
def get(default_fname=None): """ Returns a logger instance, with optional log file output. """ global log if log is not None: return log fname = os.environ.get('LOGTO', None) if fname is None: fname = default_fname log = Logger(fname) return log
Example #15
Source File: logger.py From tensorflow-forward-ad with MIT License | 5 votes |
def get(fname=None): """ Returns a logger instance, with optional log file output. """ global log if log is not None and fname is None: return log # fname = os.environ.get('LOGTO', None) # if fname is None: # fname = default_fname else: log = Logger(fname) return log
Example #16
Source File: logger.py From inc-few-shot-attractor-public with MIT License | 5 votes |
def get(fname=None): """ Returns a logger instance, with optional log file output. """ global log if log is not None and fname is None: return log # fname = os.environ.get("LOGTO", None) # if fname is None: # fname = default_fname else: log = Logger(fname) return log
Example #17
Source File: option_saver.py From rec-attend-public with MIT License | 5 votes |
def __init__(self, folder, name): if not os.path.exists(folder): os.makedirs(folder) self.folder = folder self.log = logger.get() self.fname = os.path.join(folder, name + '.yaml')
Example #18
Source File: concurrent_batch_iter.py From rec-attend-public with MIT License | 5 votes |
def next(self): if self._stopped: raise StopIteration self.scan(do_print=(self.counter % self.log_queue == 0)) if self.counter % self.log_queue == 0: self.counter = 0 batch = self.q.get() self.q.task_done() self.counter += 1 while batch is None: self.info("Got an empty batch. Ending iteration.") self.relaunch = False try: batch = self.q.get(False) self.q.task_done() qempty = False except queue.Empty: qempty = True pass if qempty: self.info("Queue empty. Scanning for alive thread.") # Scan for alive thread. found_alive = False for ff in self.fetchers: if ff.is_alive(): found_alive = True break self.info("No alive thread found. Joining.") # If no alive thread, join all. if not found_alive: for ff in self.fetchers: ff.join() self._stopped = True raise StopIteration else: self.info("Got another batch from the queue.") return batch
Example #19
Source File: concurrent_batch_iter.py From rec-attend-public with MIT License | 5 votes |
def run(self): while not self.stopped(): try: self.q.get(False) self.q.task_done() except queue.Empty: pass
Example #20
Source File: concurrent_batch_iter.py From rec-attend-public with MIT License | 5 votes |
def __init__(self, q, batch_iter): super(BatchProducer, self).__init__() threading.Thread.__init__(self) self.q = q self.batch_iter = batch_iter self.log = logger.get() self._stop = threading.Event() self.daemon = True
Example #21
Source File: saver.py From rec-attend-public with MIT License | 5 votes |
def __init__(self, folder, model_opt=None, data_opt=None): if not os.path.exists(folder): os.makedirs(folder) self.folder = folder self.log = logger.get() self.tf_saver = None if model_opt is not None: self.save_opt(os.path.join(folder, kModelOptFilename), model_opt) if data_opt is not None: self.save_opt(os.path.join(folder, kDatasetOptFilename), data_opt)
Example #22
Source File: batch_iter.py From rec-attend-public with MIT License | 4 votes |
def __init__(self, num, batch_size=1, progress_bar=False, log_epoch=10, get_fn=None, cycle=False, shuffle=True, stagnant=False, seed=2, num_batches=-1): """Construct a batch iterator. Args: data: numpy.ndarray, (N, D), N is the number of examples, D is the feature dimension. labels: numpy.ndarray, (N), N is the number of examples. batch_size: int, batch size. """ self._num = num self._batch_size = batch_size self._step = 0 self._num_steps = int(np.ceil(self._num / float(batch_size))) if num_batches > 0: self._num_steps = min(self._num_steps, num_batches) self._pb = None self._variables = None self._get_fn = get_fn self.get_fn = get_fn self._cycle = cycle self._shuffle_idx = np.arange(self._num) self._shuffle = shuffle self._random = np.random.RandomState(seed) if shuffle: self._random.shuffle(self._shuffle_idx) self._shuffle_flag = False self._stagnant = stagnant self._log_epoch = log_epoch self._log = logger.get() self._epoch = 0 if progress_bar: self._pb = pb.get(self._num_steps) pass self._mutex = threading.Lock() pass
Example #23
Source File: thermostat.py From bt-mqtt-gateway with MIT License | 4 votes |
def present_device_state(self, name, thermostat): from eq3bt import Mode ret = [] attributes = {} for attr in monitoredAttrs: value = getattr(thermostat, attr) ret.append(MqttMessage(topic=self.format_topic(name, attr), payload=value)) if attr != SENSOR_TARGET_TEMPERATURE: attributes[attr] = value if thermostat.away_end: attributes[SENSOR_AWAY_END] = thermostat.away_end.isoformat() else: attributes[SENSOR_AWAY_END] = None ret.append( MqttMessage( topic=self.format_topic(name, "json_attributes"), payload=attributes ) ) mapping = { Mode.Auto: STATE_AUTO, Mode.Closed: STATE_OFF, Mode.Boost: STATE_AUTO, } mode = mapping.get(thermostat.mode, STATE_HEAT) if thermostat.mode == Mode.Boost: hold = HOLD_BOOST elif thermostat.mode == Mode.Away: hold = "off" elif thermostat.target_temperature == thermostat.comfort_temperature: hold = HOLD_COMFORT elif thermostat.target_temperature == thermostat.eco_temperature: hold = HOLD_ECO else: hold = HOLD_NONE ret.append(MqttMessage(topic=self.format_topic(name, "mode"), payload=mode)) ret.append(MqttMessage(topic=self.format_topic(name, "hold"), payload=hold)) ret.append( MqttMessage( topic=self.format_topic(name, "away"), payload=self.true_false_to_ha_on_off(thermostat.mode == Mode.Away), ) ) return ret
Example #24
Source File: batch_iter.py From revnet-public with MIT License | 4 votes |
def __init__(self, num, batch_size=1, progress_bar=False, log_epoch=10, get_fn=None, cycle=False, shuffle=True, stagnant=False, seed=2, num_batches=-1): """Construct a batch iterator. Args: data: numpy.ndarray, (N, D), N is the number of examples, D is the feature dimension. labels: numpy.ndarray, (N), N is the number of examples. batch_size: int, batch size. """ self._num = num self._batch_size = batch_size self._step = 0 self._num_steps = int(np.ceil(self._num / float(batch_size))) if num_batches > 0: self._num_steps = min(self._num_steps, num_batches) self._pb = None self._variables = None self._get_fn = get_fn self.get_fn = get_fn self._cycle = cycle self._shuffle_idx = np.arange(self._num) self._shuffle = shuffle self._random = np.random.RandomState(seed) if shuffle: self._random.shuffle(self._shuffle_idx) self._shuffle_flag = False self._stagnant = stagnant self._log_epoch = log_epoch self._log = logger.get() self._epoch = 0 if progress_bar: self._pb = pb.get(self._num_steps) pass self._mutex = threading.Lock() pass