Fix #13: Don't modify datetime format on output
Current code would modify the datetime format on the output file adding 000 to the microseconds count, so an input of "2016-03-07 12:15:27.805" would become "2016-03-07 12:15:27.805000". This patch changes the way we output the datetime, and instead of using the datetime object used for sorting we will output the original datetime string. This will probably be useful later when we support custom log formats or other log sources.
This commit is contained in:
parent
93d7d89017
commit
546a34ff09
|
@ -52,9 +52,9 @@ will use the original file path instead of the [ALIAS]
|
|||
|
||||
The previous example would produce something like this::
|
||||
|
||||
2015-08-25 09:37:15.463000 [NS1] 15062 DEBUG neutron.context [req-b751a750-f5d8-4b6e-9af3-82d143ef9416 None] Arguments dropped when creating context: {u'project_name': None, u'tenant': None} __init__ /usr/lib/python2.7/site-packages/neutron/context.py:83
|
||||
2015-08-25 09:37:15.463000 [NS1] 15062 DEBUG neutron.plugins.ml2.db [req-b751a750-f5d8-4b6e-9af3-82d143ef9416 None] get_ports_and_sgs() called for port_ids [u'4136d577-e02f-47c1-b543-f0bfd65ef85e', u'5d5ea109-4807-4df3-bef4-b5d89c3ffebc', u'6adcffbf-09d5-4a85-9339-9d6beb2bf82c', u'6b4d7b51-c87d-483e-9606-0e2a54ad8184', u'743ccaa6-7ed9-4195-aabd-3d55006338e1', u'dc662767-61a5-4807-b2ed-a7c76b541fd6', u'4decdd33-6f13-46df-b2f0-d9ff99878514', u'34b826df-9787-443c-9bef-084374827a85', u'7bbc404b-3df7-498a-b6fb-e81f9370a19f', u'c12e6e06-ff6a-44dc-b75f-78ec55dd3dd3', u'586cd86d-59d0-434b-ab27-76975ce5abc4', u'79b33879-3232-4b3a-a27c-c0a79da10379', u'ba6a28cc-9851-4cd7-acae-40034a19c761', u'05c4115a-da58-41db-b3f7-7326e1a22971'] get_ports_and_sgs /usr/lib/python2.7/site-packages/neutron/plugins/ml2/db.py:224
|
||||
2015-08-25 09:37:15.463000 [OVS1] 12613 DEBUG neutron.agent.linux.utils [req-588c942a-6526-464f-a447-782a5e2d436a None]
|
||||
2015-08-25 09:37:15.463 [NS1] 15062 DEBUG neutron.context [req-b751a750-f5d8-4b6e-9af3-82d143ef9416 None] Arguments dropped when creating context: {u'project_name': None, u'tenant': None} __init__ /usr/lib/python2.7/site-packages/neutron/context.py:83
|
||||
2015-08-25 09:37:15.463 [NS1] 15062 DEBUG neutron.plugins.ml2.db [req-b751a750-f5d8-4b6e-9af3-82d143ef9416 None] get_ports_and_sgs() called for port_ids [u'4136d577-e02f-47c1-b543-f0bfd65ef85e', u'5d5ea109-4807-4df3-bef4-b5d89c3ffebc', u'6adcffbf-09d5-4a85-9339-9d6beb2bf82c', u'6b4d7b51-c87d-483e-9606-0e2a54ad8184', u'743ccaa6-7ed9-4195-aabd-3d55006338e1', u'dc662767-61a5-4807-b2ed-a7c76b541fd6', u'4decdd33-6f13-46df-b2f0-d9ff99878514', u'34b826df-9787-443c-9bef-084374827a85', u'7bbc404b-3df7-498a-b6fb-e81f9370a19f', u'c12e6e06-ff6a-44dc-b75f-78ec55dd3dd3', u'586cd86d-59d0-434b-ab27-76975ce5abc4', u'79b33879-3232-4b3a-a27c-c0a79da10379', u'ba6a28cc-9851-4cd7-acae-40034a19c761', u'05c4115a-da58-41db-b3f7-7326e1a22971'] get_ports_and_sgs /usr/lib/python2.7/site-packages/neutron/plugins/ml2/db.py:224
|
||||
2015-08-25 09:37:15.463 [OVS1] 12613 DEBUG neutron.agent.linux.utils [req-588c942a-6526-464f-a447-782a5e2d436a None]
|
||||
Command: ['sudo', 'neutron-rootwrap', '/etc/neutron/rootwrap.conf', 'ovs-vsctl', '--timeout=10', 'list-ports', 'br-int']
|
||||
Exit code: 0
|
||||
Stdout: 'ha-2cdba01d-e4\nha-44dca3a9-44\nha-499d3db7-97\nha-55a19f5e-ef\nha-b2d04f15-f2\nha-b5b271a1-d8\nha-fa58d644-81\nint-br-enp7s0\nint-br-ex\nqr-34b826df-97\nqr-5d5ea109-48\nqr-6adcffbf-09\nqr-743ccaa6-7e\nqr-79b33879-32\nqr-c12e6e06-ff\nqr-dc662767-61\n'
|
||||
|
|
|
@ -122,7 +122,8 @@ class OpenStackLog:
|
|||
datetime_str, "%Y-%m-%d %H:%M:%S.%f")
|
||||
pid, level = chunks[2], chunks[3]
|
||||
rest = ' '.join(chunks[4:])
|
||||
return (date_object, self._filename, pid, level, rest)
|
||||
return (date_object, datetime_str, self._filename, pid, level,
|
||||
rest)
|
||||
except IndexError:
|
||||
return None
|
||||
|
||||
|
@ -149,8 +150,8 @@ class OpenStackLog:
|
|||
# it's a non-dated line, just append to the entry
|
||||
# extra info
|
||||
if entry:
|
||||
(date_object, filename, pid, level, rest) = entry
|
||||
entry = (date_object, filename, pid, level,
|
||||
(date_object, date_str, filename, pid, level, rest) = entry
|
||||
entry = (date_object, date_str, filename, pid, level,
|
||||
rest + EXTRALINES_PADDING + line)
|
||||
|
||||
def __next__(self):
|
||||
|
@ -229,11 +230,9 @@ def process_logs(cfg):
|
|||
method = process_logs_memory_hog
|
||||
|
||||
for entry in method(logs):
|
||||
(date_object, filename, pid, level, rest) = entry
|
||||
print (' '.join(
|
||||
[date_object.strftime("%Y-%m-%d %H:%M:%S.%f"),
|
||||
'[%s]' % alias[filename], pid,
|
||||
level, rest]).rstrip('\n'))
|
||||
(date_object, date_str, filename, pid, level, rest) = entry
|
||||
print (' '.join([date_str, '[%s]' % alias[filename], pid,
|
||||
level, rest]).rstrip('\n'))
|
||||
|
||||
|
||||
def get_path_and_alias(filename, log_base, log_postfix):
|
||||
|
@ -415,12 +414,12 @@ one has not been provided:'
|
|||
- 0: means disabled, and will return the full file.
|
||||
Ex:
|
||||
$ oslogmerger -b /var/log/cinder -p .log api scheduler
|
||||
2016-02-01 10:23:34.680000 [/var/log/cinder/api.log] ...
|
||||
2016-02-01 10:24:34.680000 [/var/log/cinder/scheduler.log] ...
|
||||
2016-02-01 10:23:34.680 [/var/log/cinder/api.log] ...
|
||||
2016-02-01 10:24:34.680 [/var/log/cinder/scheduler.log] ...
|
||||
- 1: use filename without prefix or postfix.
|
||||
$ oslogmerger -a1 -b /var/log/cinder -p .log api scheduler
|
||||
2016-02-01 10:23:34.680000 [api] ...
|
||||
2016-02-01 10:24:34.680000 [scheduler] ...
|
||||
2016-02-01 10:23:34.680 [api] ...
|
||||
2016-02-01 10:24:34.680 [scheduler] ...
|
||||
- 2: same as level 1, but it will also remove filename extensions if they
|
||||
have not been defined with the postfix, will reduce log filenames
|
||||
(volume=VOL, scheduler=SCH, backup=BAK, ...) and immediate directory
|
||||
|
@ -428,19 +427,19 @@ one has not been provided:'
|
|||
directories.
|
||||
Ex:
|
||||
$ oslogmerger -a2 node?/var/log/{cinder,nova}/*.log
|
||||
2016-02-01 10:23:34.680000 [node1/C-API] ...
|
||||
2016-02-01 10:24:34.680000 [node1/C-SCH]
|
||||
2016-02-01 10:25:34.680000 [node1/C-VOL]
|
||||
2016-02-01 10:26:34.680000 [node1/N-API]
|
||||
2016-02-01 10:27:34.680000 [node2/N-CPU]
|
||||
2016-02-01 10:23:34.680 [node1/C-API] ...
|
||||
2016-02-01 10:24:34.680 [node1/C-SCH]
|
||||
2016-02-01 10:25:34.680 [node1/C-VOL]
|
||||
2016-02-01 10:26:34.680 [node1/N-API]
|
||||
2016-02-01 10:27:34.680 [node2/N-CPU]
|
||||
- 3: same as level 2, plus reduce directory names
|
||||
Ex:
|
||||
$ oslogmerger -a3 node?/var/log/{cinder,nova}/*.log
|
||||
2016-02-01 10:23:34.680000 [1/C-API] ...
|
||||
2016-02-01 10:24:34.680000 [1/C-SCH]
|
||||
2016-02-01 10:25:34.680000 [1/C-VOL]
|
||||
2016-02-01 10:26:34.680000 [1/N-API]
|
||||
2016-02-01 10:27:34.680000 [2/N-CPU]
|
||||
2016-02-01 10:23:34.680 [1/C-API] ...
|
||||
2016-02-01 10:24:34.680 [1/C-SCH]
|
||||
2016-02-01 10:25:34.680 [1/C-VOL]
|
||||
2016-02-01 10:26:34.680 [1/N-API]
|
||||
2016-02-01 10:27:34.680 [2/N-CPU]
|
||||
"""
|
||||
|
||||
parser = MyParser(description=general_description, version=__version__,
|
||||
|
|
Loading…
Reference in New Issue