Index

lognestmonster / 11d9af7

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

Latest Commit

{#}TimeHashSubjectAuthor#(+)(-)GPG?
7524 Aug 2019 21:51988a3ffbegin writing deserialization methodJosh Stockin1680N

Blob @ lognestmonster / tests / write.py

application/x-python1130 bytesdownload raw
1#!/usr/bin/env python
2
3import sys
4import os
5import time
6import ctypes
7
8def exists(f):
9 return os.path.isfile(f) or os.path.isdir(f)
10
11def milli():
12 return int(round(time.time() * 1000))
13
14def enc(string):
15 return string.encode("latin-1")
16
17def ushort(n):
18 return ctypes.c_ushort(n)
19
20def uchar(n):
21 return ctypes.c_ubyte(n)
22
23def ulonglong(n):
24 return ctypes.c_ulonglong(n)
25
26if __name__ == "__main__":
27 try:
28 out = sys.argv[1]
29 except:
30 print("must provide an out location")
31 exit(1)
32
33 version = uchar(1)
34 queue_time = ulonglong(milli())
35 open_statement = uchar(0)
36 close_statement = uchar(1)
37 open_event = uchar(2)
38 close_event = uchar(3)
39
40 ts2 = ulonglong(milli())
41 verbosity = uchar(0)
42
43 tag = enc("INIT")
44 tag_len = uchar(len(tag))
45
46 message = enc("HELLO")
47 message_len = ushort(len(message))
48
49 try:
50 f = open(out, "wb")
51
52 f.write(version)
53 f.write(queue_time)
54 f.write(open_event)
55 f.write(open_statement)
56 f.write(ts2)
57 f.write(verbosity)
58 f.write(tag_len)
59 f.write(tag)
60 f.write(message_len)
61 f.write(message)
62 f.write(close_statement)
63 f.write(close_event)
64 finally:
65 f.close()
66 print(os.stat(out).st_size)
67
68
69