Index

lognestmonster / 6177dd6

A general-purpose single-header C logging library and parser for event-based logs. (Incomplete)

Latest Commit

{#}TimeHashSubjectAuthor#(+)(-)GPG?
9407 Sep 2019 22:046177dd6updatesJosh Stockin111N

Blob @ lognestmonster / tests / write_many.py

application/x-python2376 bytesdownload raw
1#!/usr/bin/env python3
2
3# lognestmonster Copyright (c) 2019 Joshua 'joshuas3' Stockin
4# <https://github.com/JoshuaS3/lognestmonster/>.
5
6
7# This file is part of lognestmonster.
8
9# lognestmonster is free software: you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation, either version 3 of the License, or
12# (at your option) any later version.
13
14# lognestmonster is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17# GNU General Public License for more details.
18
19# You should have received a copy of the GNU General Public License
20# along with lognestmonster. If not, see <https://www.gnu.org/licenses/>.
21
22import sys
23import os
24import time
25import ctypes
26import random
27
28def exists(f):
29 return os.path.isfile(f) or os.path.isdir(f)
30
31def milli():
32 return int(round(time.time() * 1000))
33
34def enc(string):
35 return string.encode("utf-8")
36
37def ushort(n):
38 return ctypes.c_ushort(n)
39
40def uchar(n):
41 return ctypes.c_ubyte(n)
42
43def ulonglong(n):
44 return ctypes.c_ulonglong(n)
45
46def s(n=20):
47 l = int(random.random()*n)
48 st = ""
49 for i in range(0, l):
50 c = 97+int(random.random()*25)
51 st += chr(c)
52 return st
53
54if __name__ == "__main__":
55 try:
56 out = sys.argv[1]
57 except:
58 print("must provide an out location")
59 exit(1)
60
61 try:
62 count = int(sys.argv[2])
63 except:
64 print("must provide a statement count")
65 exit(1)
66
67 version = uchar(1)
68 queue_time = ulonglong(milli())
69 open_statement = uchar(0)
70 close_statement = uchar(1)
71 open_event = uchar(2)
72 close_event = uchar(3)
73
74 verbosity = uchar(0)
75
76 start = milli()
77
78 try:
79 f = open(out, "wb")
80
81 f.write(version)
82 f.write(queue_time)
83
84 f.write(open_event)
85 for i in range(0, count):
86 print("{0}%".format(round((i/count)*1000)/10), end="\r")
87 ts = ulonglong(milli())
88
89 tag = enc(s(10))
90 tag_len = uchar(len(tag))
91
92 message = enc(s(20))
93 message_len = ushort(len(message))
94 f.write(open_statement)
95 f.write(ts)
96 f.write(verbosity)
97 f.write(tag_len)
98 f.write(tag)
99 f.write(message_len)
100 f.write(message)
101 f.write(close_statement)
102 f.write(close_event)
103
104 finally:
105 f.close()
106 print("file written with size {0}MB in {1} seconds".format(round(os.stat(out).st_size/1000)/1000, (milli()-start)/1000))
107
108
109