k-space
/
mongo-logger
Archived
9
0
Fork 0

Formatting fixes

This commit is contained in:
Lauri Võsandi 2021-07-05 15:44:44 +03:00
parent 560717fc2b
commit 75c6f50425
4 changed files with 21 additions and 7 deletions

6
.flake8 Normal file
View File

@ -0,0 +1,6 @@
[flake8]
inline-quotes = "
multiline-quotes = """
indent-size = 4
max-line-length = 160
ignore = Q003 E128 E704 E731

6
.pre-commit-config.yaml Normal file
View File

@ -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]

View File

@ -14,6 +14,7 @@ EXPIRE_AFTER_SECONDS = int(os.getenv("EXPIRE_AFTER_SECONDS", "1209600"))
db = AsyncIOMotorClient(MONGO_URI).get_default_database()
db.log.create_index("time", expireAfterSeconds=EXPIRE_AFTER_SECONDS)
class Server(object):
def __init__(self):
self._loop = asyncio.get_event_loop()
@ -35,14 +36,14 @@ class Server(object):
tag, time, record, options = obj
try:
seconds, nanoseconds = struct.unpack(">II", time.data)
record["time"] = datetime.fromtimestamp(seconds).replace(microsecond=int(nanoseconds/1000))
record["time"] = datetime.fromtimestamp(seconds).replace(microsecond=int(nanoseconds / 1000))
except AttributeError:
record["time"] = datetime.fromtimestamp(time)
assert not options, "Can't handle options"
record.pop("container_id", None)
record["host"] = FQDN
result = await db.log.insert_one(record)
await db.log.insert_one(record)
async def main():

View File

@ -15,13 +15,14 @@ if not MONGO_URI:
db = AsyncIOMotorClient(MONGO_URI).get_default_database()
parser = argparse.ArgumentParser()
parser.add_argument('--include-container', action='append', default=[])
parser.add_argument('--exclude-container', action='append', default=[])
parser.add_argument('--exclude-host', action='append', default=[])
parser.add_argument("--include-container", action="append", default=[])
parser.add_argument("--exclude-container", action="append", default=[])
parser.add_argument("--exclude-host", action="append", default=[])
args = parser.parse_args()
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")
async for event in stream:
doc = event["fullDocument"]
@ -44,7 +45,7 @@ async def main():
m = re.match("time=\".*?\" level=[a-z]+ msg=\"(.*?)\"", msg)
if m:
msg, = m.groups()
m = re.match("\[\d+.*? \d+\] (.*?)\"", msg)
m = re.match(r"\[\d+.*? \d+\] (.*?)\"", msg)
if m:
msg, = m.groups()
print(doc["time"], colored(doc.get("host", "-"), "blue"), "\t", "% 30s" % colored(container_name, "yellow"), msg)