Formatting fixes
This commit is contained in:
parent
560717fc2b
commit
75c6f50425
|
@ -0,0 +1,6 @@
|
||||||
|
[flake8]
|
||||||
|
inline-quotes = "
|
||||||
|
multiline-quotes = """
|
||||||
|
indent-size = 4
|
||||||
|
max-line-length = 160
|
||||||
|
ignore = Q003 E128 E704 E731
|
|
@ -0,0 +1,6 @@
|
||||||
|
repos:
|
||||||
|
- repo: https://github.com/PyCQA/flake8
|
||||||
|
rev: 3.9.2
|
||||||
|
hooks:
|
||||||
|
- id: flake8
|
||||||
|
additional_dependencies: [flake8-typing-imports==1.10.0,flake8-quotes==3.2.0]
|
|
@ -14,6 +14,7 @@ EXPIRE_AFTER_SECONDS = int(os.getenv("EXPIRE_AFTER_SECONDS", "1209600"))
|
||||||
db = AsyncIOMotorClient(MONGO_URI).get_default_database()
|
db = AsyncIOMotorClient(MONGO_URI).get_default_database()
|
||||||
db.log.create_index("time", expireAfterSeconds=EXPIRE_AFTER_SECONDS)
|
db.log.create_index("time", expireAfterSeconds=EXPIRE_AFTER_SECONDS)
|
||||||
|
|
||||||
|
|
||||||
class Server(object):
|
class Server(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self._loop = asyncio.get_event_loop()
|
self._loop = asyncio.get_event_loop()
|
||||||
|
@ -42,7 +43,7 @@ class Server(object):
|
||||||
|
|
||||||
record.pop("container_id", None)
|
record.pop("container_id", None)
|
||||||
record["host"] = FQDN
|
record["host"] = FQDN
|
||||||
result = await db.log.insert_one(record)
|
await db.log.insert_one(record)
|
||||||
|
|
||||||
|
|
||||||
async def main():
|
async def main():
|
||||||
|
|
11
tailer.py
11
tailer.py
|
@ -15,13 +15,14 @@ if not MONGO_URI:
|
||||||
db = AsyncIOMotorClient(MONGO_URI).get_default_database()
|
db = AsyncIOMotorClient(MONGO_URI).get_default_database()
|
||||||
|
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument('--include-container', action='append', default=[])
|
parser.add_argument("--include-container", action="append", default=[])
|
||||||
parser.add_argument('--exclude-container', action='append', default=[])
|
parser.add_argument("--exclude-container", action="append", default=[])
|
||||||
parser.add_argument('--exclude-host', action='append', default=[])
|
parser.add_argument("--exclude-host", action="append", default=[])
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
async def main():
|
async def main():
|
||||||
async with db.log.watch([{'$match': {'operationType': 'insert'}}]) as stream:
|
async with db.log.watch([{"$match": {"operationType": "insert"}}]) as stream:
|
||||||
print("Connected")
|
print("Connected")
|
||||||
async for event in stream:
|
async for event in stream:
|
||||||
doc = event["fullDocument"]
|
doc = event["fullDocument"]
|
||||||
|
@ -44,7 +45,7 @@ async def main():
|
||||||
m = re.match("time=\".*?\" level=[a-z]+ msg=\"(.*?)\"", msg)
|
m = re.match("time=\".*?\" level=[a-z]+ msg=\"(.*?)\"", msg)
|
||||||
if m:
|
if m:
|
||||||
msg, = m.groups()
|
msg, = m.groups()
|
||||||
m = re.match("\[\d+.*? \d+\] (.*?)\"", msg)
|
m = re.match(r"\[\d+.*? \d+\] (.*?)\"", msg)
|
||||||
if m:
|
if m:
|
||||||
msg, = m.groups()
|
msg, = m.groups()
|
||||||
print(doc["time"], colored(doc.get("host", "-"), "blue"), "\t", "% 30s" % colored(container_name, "yellow"), msg)
|
print(doc["time"], colored(doc.get("host", "-"), "blue"), "\t", "% 30s" % colored(container_name, "yellow"), msg)
|
||||||
|
|
Reference in New Issue