1/16/17
--------------------------
_node1.log:_
...
2017-01-16 10:37:48.717 Snapchat[12345:1234567] Something something Foo.
2017-01-16 10:37:49.677 Snapchat[12345:1234567] Something something xyz.
2017-01-16 10:37:49.717 Snapchat[12345:1234567] Something something zyx.
2017-01-16 10:37:50.200 Snapchat[12345:1234567] Something something Bar.
2017-01-16 10:37:51.300 Snapchat[12345:1234567] Something something Foo2.
2017-01-16 10:37:52.301 Snapchat[12345:1234567] Something something Foo2.
2017-01-16 10:37:52.711 Snapchat[12345:1234567] Something something Bar2.
2017-01-16 10:37:52.711 Snapchat[12345:1234567] Something something Bar2.
2017-01-16 10:37:52.717 Snapchat[12345:1234567] Something something Foo.
...
_node2.log:_
...
2017-01-16 10:37:48.716 Snapchat[12345:1234567] Something something Foo.
2017-01-16 10:37:49.678 Snapchat[12345:1234567] Something something xyz.
2017-01-16 10:37:49.718 Snapchat[12345:1234567] Something something zyx.
2017-01-16 10:37:50.201 Snapchat[12345:1234567] Something something Bar.
2017-01-16 10:37:51.300 Snapchat[12345:1234567] Something something Foo2.
2017-01-16 10:37:52.301 Snapchat[12345:1234567] Something something Foo2.
2017-01-16 10:37:52.811 Snapchat[12345:1234567] Something something Bar2.
2017-01-16 10:37:52.811 Snapchat[12345:1234567] Something something Bar2.
2017-01-16 10:37:53.717 Snapchat[12345:1234567] Something something Foo.
2017-01-16 10:38:48.716 Snapchat[12345:1234567] Something something something.
2017-01-16 10:38:49.678 Snapchat[12345:1234567] Something.
2017-01-16 10:38:49.718 Snapchat[12345:1234567] Something zyx.
2017-01-16 10:38:50.201 Snapchat[12345:1234567] Something Bar.
2017-01-16 10:38:51.300 Snapchat[12345:1234567] Something Foo2.
2017-01-16 10:38:52.301 Snapchat[12345:1234567] Something Fuzz2.
2017-01-16 10:38:52.811 Snapchat[12345:1234567] Something Buzz2.
2017-01-16 10:38:52.811 Snapchat[12345:1234567] Something Bash2.
2017-01-16 10:38:53.717 Snapchat[12345:1234567] Something Foo.
...
_Output File (From aggregating the input files above):_
...
node1.log 2014-10-19 13:37:48.717 Snapchat[12345:1234567] Something something Foo.
node2.log 2014-10-19 13:38:01.454 Snapchat[12345:7654321] Something something Foo2.
node2.log 2014-10-19 13:38:02.600 Snapchat[12345:7654321] Something something Bar2.
node1.log 2014-10-19 13:38:50.200 Snapchat[12345:1234567] Something something Bar.
node2.log 2014-10-19 13:38:50.201 Snapchat[12345:7654321] Something something Baz2.
node1.log 2014-10-19 13:38:51.392 Snapchat[12345:1234567] Something something Baz.
...
So we want to implement a function :
public File logAggregator (File... files) {
// TODO
}
That takes in some list of files and outputs the unified log output sorted by timestamp
STDIN:
node1.log:
2017-01-16 10:37:48.717 Snapchat[12345:1234567] Something something Foo.
2017-01-16 10:37:49.677 Snapchat[12345:1234567] Something something xyz.
2017-01-16 10:37:49.717 Snapchat[12345:1234567] Something something zyx.
2017-01-16 10:37:50.200 Snapchat[12345:1234567] Something something Bar.
2017-01-16 10:37:51.300 Snapchat[12345:1234567] Something something Foo2.
2017-01-16 10:37:52.301 Snapchat[12345:1234567] Something something Foo2.
2017-01-16 10:37:52.711 Snapchat[12345:1234567] Something something Bar2.
2017-01-16 10:37:52.711 Snapchat[12345:1234567] Something something Bar2.
2017-01-16 10:37:52.717 Snapchat[12345:1234567] Something something Foo.
node2.log:
2017-01-16 10:37:48.716 Snapchat[12345:1234567] Something something Foo.
2017-01-16 10:37:49.678 Snapchat[12345:1234567] Something something xyz.
2017-01-16 10:37:49.718 Snapchat[12345:1234567] Something something zyx.
2017-01-16 10:37:50.201 Snapchat[12345:1234567] Something something Bar.
2017-01-16 10:37:51.300 Snapchat[12345:1234567] Something something Foo2.
2017-01-16 10:37:52.301 Snapchat[12345:1234567] Something something Foo2.
2017-01-16 10:37:52.811 Snapchat[12345:1234567] Something something Bar2.
2017-01-16 10:37:52.811 Snapchat[12345:1234567] Something something Bar2.
2017-01-16 10:37:53.717 Snapchat[12345:1234567] Something something Foo.
2017-01-16 10:38:48.716 Snapchat[12345:1234567] Something something something.
2017-01-16 10:38:49.678 Snapchat[12345:1234567] Something.
2017-01-16 10:38:49.718 Snapchat[12345:1234567] Something zyx.
2017-01-16 10:38:50.201 Snapchat[12345:1234567] Something Bar.
2017-01-16 10:38:51.300 Snapchat[12345:1234567] Something Foo2.
2017-01-16 10:38:52.301 Snapchat[12345:1234567] Something Fuzz2.
2017-01-16 10:38:52.811 Snapchat[12345:1234567] Something Buzz2.
2017-01-16 10:38:52.811 Snapchat[12345:1234567] Something Bash2.
2017-01-16 10:38:53.717 Snapchat[12345:1234567] Something Foo.
# def logAggregator (file1, file2):
# # mydict = defaultdict(list)
# mylist1 = mylist2 = []
# for line in open(file1, 'r'):
# # mydict[file1].append(line)
# mylist1.append((line, file1))
# for line in open(file2, 'r'):
# # mydict[file2].append(line)
# mylist2.append((line, file2))
# mylist = mylist1 + mylist2
# mylist = sorted(mylist)
# output = [ (y, x) for (x, y) in mylist]
import sys
def logAggregator ():
mylist = []
for line in sys.stdin:
if 'node1.log' in line:
tag = 'node1.log'
continue
if 'node2.log' in line:
tag = 'node2.log'
continue
if not line:
continue
mylist.append((line, tag))
mylist = sorted(mylist)
return [ (y, x) for (x, y) in mylist]
myoutput = logAggregator()
for (x,y) in myoutput:
print x, y,
--------------------------
_node1.log:_
...
2017-01-16 10:37:48.717 Snapchat[12345:1234567] Something something Foo.
2017-01-16 10:37:49.677 Snapchat[12345:1234567] Something something xyz.
2017-01-16 10:37:49.717 Snapchat[12345:1234567] Something something zyx.
2017-01-16 10:37:50.200 Snapchat[12345:1234567] Something something Bar.
2017-01-16 10:37:51.300 Snapchat[12345:1234567] Something something Foo2.
2017-01-16 10:37:52.301 Snapchat[12345:1234567] Something something Foo2.
2017-01-16 10:37:52.711 Snapchat[12345:1234567] Something something Bar2.
2017-01-16 10:37:52.711 Snapchat[12345:1234567] Something something Bar2.
2017-01-16 10:37:52.717 Snapchat[12345:1234567] Something something Foo.
...
_node2.log:_
...
2017-01-16 10:37:48.716 Snapchat[12345:1234567] Something something Foo.
2017-01-16 10:37:49.678 Snapchat[12345:1234567] Something something xyz.
2017-01-16 10:37:49.718 Snapchat[12345:1234567] Something something zyx.
2017-01-16 10:37:50.201 Snapchat[12345:1234567] Something something Bar.
2017-01-16 10:37:51.300 Snapchat[12345:1234567] Something something Foo2.
2017-01-16 10:37:52.301 Snapchat[12345:1234567] Something something Foo2.
2017-01-16 10:37:52.811 Snapchat[12345:1234567] Something something Bar2.
2017-01-16 10:37:52.811 Snapchat[12345:1234567] Something something Bar2.
2017-01-16 10:37:53.717 Snapchat[12345:1234567] Something something Foo.
2017-01-16 10:38:48.716 Snapchat[12345:1234567] Something something something.
2017-01-16 10:38:49.678 Snapchat[12345:1234567] Something.
2017-01-16 10:38:49.718 Snapchat[12345:1234567] Something zyx.
2017-01-16 10:38:50.201 Snapchat[12345:1234567] Something Bar.
2017-01-16 10:38:51.300 Snapchat[12345:1234567] Something Foo2.
2017-01-16 10:38:52.301 Snapchat[12345:1234567] Something Fuzz2.
2017-01-16 10:38:52.811 Snapchat[12345:1234567] Something Buzz2.
2017-01-16 10:38:52.811 Snapchat[12345:1234567] Something Bash2.
2017-01-16 10:38:53.717 Snapchat[12345:1234567] Something Foo.
...
_Output File (From aggregating the input files above):_
...
node1.log 2014-10-19 13:37:48.717 Snapchat[12345:1234567] Something something Foo.
node2.log 2014-10-19 13:38:01.454 Snapchat[12345:7654321] Something something Foo2.
node2.log 2014-10-19 13:38:02.600 Snapchat[12345:7654321] Something something Bar2.
node1.log 2014-10-19 13:38:50.200 Snapchat[12345:1234567] Something something Bar.
node2.log 2014-10-19 13:38:50.201 Snapchat[12345:7654321] Something something Baz2.
node1.log 2014-10-19 13:38:51.392 Snapchat[12345:1234567] Something something Baz.
...
So we want to implement a function :
public File logAggregator (File... files) {
// TODO
}
That takes in some list of files and outputs the unified log output sorted by timestamp
STDIN:
node1.log:
2017-01-16 10:37:48.717 Snapchat[12345:1234567] Something something Foo.
2017-01-16 10:37:49.677 Snapchat[12345:1234567] Something something xyz.
2017-01-16 10:37:49.717 Snapchat[12345:1234567] Something something zyx.
2017-01-16 10:37:50.200 Snapchat[12345:1234567] Something something Bar.
2017-01-16 10:37:51.300 Snapchat[12345:1234567] Something something Foo2.
2017-01-16 10:37:52.301 Snapchat[12345:1234567] Something something Foo2.
2017-01-16 10:37:52.711 Snapchat[12345:1234567] Something something Bar2.
2017-01-16 10:37:52.711 Snapchat[12345:1234567] Something something Bar2.
2017-01-16 10:37:52.717 Snapchat[12345:1234567] Something something Foo.
node2.log:
2017-01-16 10:37:48.716 Snapchat[12345:1234567] Something something Foo.
2017-01-16 10:37:49.678 Snapchat[12345:1234567] Something something xyz.
2017-01-16 10:37:49.718 Snapchat[12345:1234567] Something something zyx.
2017-01-16 10:37:50.201 Snapchat[12345:1234567] Something something Bar.
2017-01-16 10:37:51.300 Snapchat[12345:1234567] Something something Foo2.
2017-01-16 10:37:52.301 Snapchat[12345:1234567] Something something Foo2.
2017-01-16 10:37:52.811 Snapchat[12345:1234567] Something something Bar2.
2017-01-16 10:37:52.811 Snapchat[12345:1234567] Something something Bar2.
2017-01-16 10:37:53.717 Snapchat[12345:1234567] Something something Foo.
2017-01-16 10:38:48.716 Snapchat[12345:1234567] Something something something.
2017-01-16 10:38:49.678 Snapchat[12345:1234567] Something.
2017-01-16 10:38:49.718 Snapchat[12345:1234567] Something zyx.
2017-01-16 10:38:50.201 Snapchat[12345:1234567] Something Bar.
2017-01-16 10:38:51.300 Snapchat[12345:1234567] Something Foo2.
2017-01-16 10:38:52.301 Snapchat[12345:1234567] Something Fuzz2.
2017-01-16 10:38:52.811 Snapchat[12345:1234567] Something Buzz2.
2017-01-16 10:38:52.811 Snapchat[12345:1234567] Something Bash2.
2017-01-16 10:38:53.717 Snapchat[12345:1234567] Something Foo.
# def logAggregator (file1, file2):
# # mydict = defaultdict(list)
# mylist1 = mylist2 = []
# for line in open(file1, 'r'):
# # mydict[file1].append(line)
# mylist1.append((line, file1))
# for line in open(file2, 'r'):
# # mydict[file2].append(line)
# mylist2.append((line, file2))
# mylist = mylist1 + mylist2
# mylist = sorted(mylist)
# output = [ (y, x) for (x, y) in mylist]
import sys
def logAggregator ():
mylist = []
for line in sys.stdin:
if 'node1.log' in line:
tag = 'node1.log'
continue
if 'node2.log' in line:
tag = 'node2.log'
continue
if not line:
continue
mylist.append((line, tag))
mylist = sorted(mylist)
return [ (y, x) for (x, y) in mylist]
myoutput = logAggregator()
for (x,y) in myoutput:
print x, y,
Comments
Post a Comment
https://gengwg.blogspot.com/