def test_local_basic(self): # logging to local file test name = 'local.basic' log = mlogging.config(name=name, outputs=['local']) log.warning('warning') log_file = os.path.join(self.local_root, name.replace('.', '/')) tail = subprocess.Popen(["tail", log_file], stdout=subprocess.PIPE) msg = get_linestring_split(tail.stdout.read(), -1) self.assertEqual(msg[3:6], [name, 'WARNING', 'warning'])
def test_local_basic(self): # logging to local file test name = 'local.basic' log = mlogging.config(name=name, outputs=['local']) log.warning('warning') log_file = os.path.join(self.local_root, name.replace('.','/')) tail = subprocess.Popen(["tail",log_file], stdout=subprocess.PIPE) msg = get_linestring_split(tail.stdout.read(), -1) self.assertEqual(msg[3:6], [name,'WARNING','warning'])
def test_screen_basic(self): # make sure logging to screen works name = 'screen.basic' log = mlogging.config(name=name, outputs=['screen']) # redirect stream to string io to capture log.handlers[0].stream = StringIO() log.warning('warning') log_output = log.handlers[0].stream.getvalue() msg_warning = get_linestring_split(log_output, 0) self.assertEqual(msg_warning[3:6], [name,'WARNING','warning'])
def test_option(self): name = 'option.option1' log = mlogging.config(name=name, outputs=['screen']) mlogging.option(name, format_string='%(message)s') # redirect stream to string io to capture log.handlers[0].stream = StringIO() log.warning('warning') log_output = log.handlers[0].stream.getvalue() msg_warning = get_linestring_split(log_output, 0) self.assertEqual(msg_warning[0:1], ['warning']) name = 'option.option2' log = mlogging.config(name=name, outputs=['screen']) mlogging.option(name, format_string='%(levelname)s %(message)s') # redirect stream to string io to capture log.handlers[0].stream = StringIO() log.warning('warning') log_output = log.handlers[0].stream.getvalue() msg_warning = get_linestring_split(log_output, 0) self.assertEqual(msg_warning[0:2], ['WARNING','warning'])
def test_set_default(self): mlogging.set_default(format_string='%(message)s') name = 'option.set_default' log = mlogging.config(name=name, outputs=['screen']) # redirect stream to string io to capture log.handlers[0].stream = StringIO() log.warning('warning') log_output = log.handlers[0].stream.getvalue() msg_warning = get_linestring_split(log_output, 0) self.assertEqual(msg_warning[0:1], ['warning'])
def test_screen_basic(self): # make sure logging to screen works name = 'screen.basic' log = mlogging.config(name=name, outputs=['screen']) # redirect stream to string io to capture log.handlers[0].stream = StringIO() log.warning('warning') log_output = log.handlers[0].stream.getvalue() msg_warning = get_linestring_split(log_output, 0) self.assertEqual(msg_warning[3:6], [name, 'WARNING', 'warning'])
def test_option(self): name = 'option.option1' log = mlogging.config(name=name, outputs=['screen']) mlogging.option(name, format_string='%(message)s') # redirect stream to string io to capture log.handlers[0].stream = StringIO() log.warning('warning') log_output = log.handlers[0].stream.getvalue() msg_warning = get_linestring_split(log_output, 0) self.assertEqual(msg_warning[0:1], ['warning']) name = 'option.option2' log = mlogging.config(name=name, outputs=['screen']) mlogging.option(name, format_string='%(levelname)s %(message)s') # redirect stream to string io to capture log.handlers[0].stream = StringIO() log.warning('warning') log_output = log.handlers[0].stream.getvalue() msg_warning = get_linestring_split(log_output, 0) self.assertEqual(msg_warning[0:2], ['WARNING', 'warning'])
def test_combine_basic(self): # test combined logging name = 'combine.basic' log = mlogging.config(name=name, outputs=['screen','local']) # redirect stream to string io to capture log.handlers[0].stream = StringIO() log.warning('warning') log_output = log.handlers[0].stream.getvalue() screen_msg = log_output.split() self.assertEqual(screen_msg[3:6], [name,'WARNING','warning']) log_file = os.path.join(self.local_root, name.replace('.','/')) tail = subprocess.Popen(["tail",log_file], stdout=subprocess.PIPE) msg_local = get_linestring_split(tail.stdout.read(), -1) self.assertEqual(msg_local[3:6], [name,'WARNING','warning'])
def test_combine_basic(self): # test combined logging name = 'combine.basic' log = mlogging.config(name=name, outputs=['screen', 'local']) # redirect stream to string io to capture log.handlers[0].stream = StringIO() log.warning('warning') log_output = log.handlers[0].stream.getvalue() screen_msg = log_output.split() self.assertEqual(screen_msg[3:6], [name, 'WARNING', 'warning']) log_file = os.path.join(self.local_root, name.replace('.', '/')) tail = subprocess.Popen(["tail", log_file], stdout=subprocess.PIPE) msg_local = get_linestring_split(tail.stdout.read(), -1) self.assertEqual(msg_local[3:6], [name, 'WARNING', 'warning'])
def test_screen_filter(self): # make sure logging to screen works name = 'screen.filter' log = mlogging.config(name=name, outputs=['screen'], levels=['warning','debug']) # redirect stream to string io to capture log.handlers[0].stream = StringIO() log.critical('critical') log.error('error') log.warning('warning') log.info('info') log.debug('debug') log_output = log.handlers[0].stream.getvalue() msg_warning = get_linestring_split(log_output,0) self.assertEqual(msg_warning[3:6], [name,'WARNING','warning']) msg_debug = get_linestring_split(log_output,1) self.assertEqual(msg_debug[3:6], [name,'DEBUG','debug'])
def test_screen_filter(self): # make sure logging to screen works name = 'screen.filter' log = mlogging.config(name=name, outputs=['screen'], levels=['warning', 'debug']) # redirect stream to string io to capture log.handlers[0].stream = StringIO() log.critical('critical') log.error('error') log.warning('warning') log.info('info') log.debug('debug') log_output = log.handlers[0].stream.getvalue() msg_warning = get_linestring_split(log_output, 0) self.assertEqual(msg_warning[3:6], [name, 'WARNING', 'warning']) msg_debug = get_linestring_split(log_output, 1) self.assertEqual(msg_debug[3:6], [name, 'DEBUG', 'debug'])
def test_remote_basic(self): # logging to remote scribe test name = 'remote.basic' log = mlogging.config(name=name, outputs=['remote']) log.warning('warning')