Index

lognestmonster / 7b6bdef

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

Latest Commit

{#}TimeHashSubjectAuthor#(+)(-)GPG?
9302 Sep 2019 18:2023adbb8update parser stuffJosh Stockin11926N

Blob @ lognestmonster / tests / write.py

application/x-python2055 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
46if __name__ == "__main__":
47 try:
48 out = sys.argv[1]
49 except:
50 print("must provide an out location")
51 exit(1)
52
53 version = uchar(1)
54 queue_time = ulonglong(milli())
55 open_statement = uchar(0)
56 close_statement = uchar(1)
57 open_event = uchar(2)
58 close_event = uchar(3)
59
60 verbosity = uchar(0)
61 ts = ulonglong(milli())
62
63 tag = enc("INFO")
64 tag_len = uchar(len(tag))
65
66 message = enc("Hello, World!")
67 message_len = ushort(len(message))
68
69 start = milli()
70
71 try:
72 f = open(out, "wb")
73
74 f.write(version)
75 f.write(queue_time)
76
77 f.write(open_event)
78
79 f.write(open_statement)
80 f.write(ts)
81 f.write(verbosity)
82 f.write(tag_len)
83 f.write(tag)
84 f.write(message_len)
85 f.write(message)
86 f.write(close_statement)
87
88 f.write(close_event)
89
90 finally:
91 f.close()
92 print("file written with size {0}MB in {1} seconds".format(round(os.stat(out).st_size/1000)/1000, (milli()-start)/1000))
93
94
95