A general-purpose single-header C logging library and parser for event-based logs. (Incomplete)
{#} | Time | Hash | Subject | Author | # | (+) | (-) | GPG? |
---|---|---|---|---|---|---|---|---|
152 | 29 Nov 2019 19:23 | 7b6bdef | Update .gitignore for VIM temp files | Josh Stockin | 1 | 2 | 2 | N |
Object | Latest Commit Subject | Time | Hash |
---|---|---|---|
parser | Bring updates to present | 17 Nov 2019 17:06 | 13604ed |
src | Include stdio.h for printf calls | 27 Nov 2019 23:41 | d727ad6 |
static | Logo | 25 Dec 2018 19:58 | 5a96206 |
tests | Update string format typing for cross-arch usage | 26 Nov 2019 18:12 | 89785fb |
.gitignore | Update .gitignore for VIM temp files | 29 Nov 2019 19:23 | 7b6bdef |
.travis.yml | Drop Windows tests from Travis CI | 11 Sep 2019 19:58 | 78c6a12 |
HELP | Create HELP and VERSION files for output preview of appropriate parser flags | 26 Aug 2019 18:11 | a99593f |
LICENSE | Create LICENSE | 26 Dec 2018 17:01 | 9046b13 |
README.md | Update readme with build test results | 15 Sep 2019 15:31 | d00611e |
VERSION | Create HELP and VERSION files for output preview of appropriate parser flags | 26 Aug 2019 18:11 | a99593f |
appveyor.yml | another attempt | 26 Sep 2019 18:41 | 456f70b |
lognestmonster | update cross platform commands | 12 Sep 2019 18:15 | 711a196 |
test | Add -Werror flag to gcc | 25 Nov 2019 18:57 | 237d545 |
test.ps1 | another attempt | 26 Sep 2019 18:41 | 456f70b |
Multilevel logging for advanced programs.
This is subject to future change over security concerns regarding pointers and memory allocation.
class lognestmonster
enum VerbosityLevels {INFO, DEBUG, VERBOSE, VERYVERBOSE, WARNING, ERROR}
struct QueueConfig
char * out_dir // directory to output log files
virtual void * alloc(size_t size) // implementation defaults to cstd malloc()
virtual void free(void * block) // implementation defaults to cstd free()
virtual void * serialize(LogObject * obj) // implementation defaults to manual serialization of standard LogObject to allocated block
virtual bool write(void * serialized, size_t size, std::ostream stream, bool append) // implementation defaults to writing entire serialized block to stream
virtual int delete(char * file_name) // implementation defaults to cstd remove()
interface LogObject
Pushable * parent
char * temp_file
virtual bool save_temp()
virtual bool delete_temp()
interface Pushable
protected:
std::vector<LogObject *> pushed
public:
push(LogObject * obj)
push(int verbosity, char * tag, char * message) // implicitly creates a Statement and then pushes
class Queue : Pushable
public:
struct QueueConfig * _config
constructor (struct QueueConfig * config)
write() // serializes, writes, and clears pushed LogObjects
write(LogObject * obj) // implicit push(), then write()
write(int verbosity, char * tag, char * message) // implicit Statement creation, push(), then write()
class Event : LogObject, Pushable
public:
constructor (LogObject * obj) // implicit push()
constructor (int verbosity, char * tag, char * message) // implicit Statement creation, then push()
class Statement : LogObject
public:
int verbosity
int timestamp
std::string * tag
std::string * message
constructor (int verbosity, char * tag, char * message)
A Queue
handles data serialization and file writing to the main logtree file. Queue writing refers to sending serialized logtree data to the outstream. Queue pushing refers to adding an Event or Statement to the queue for future writing.
An Event
is a pushable list of statements or events, or the "nest". Event pushing refers to adding an Event or Statement to the parent's list.
A Statement
is the data-containing log item with a timestamp, verbosity level, tag/invoker, and message.
In reference to data serialization, parser
as used here is just a deserializer.
By default the library serializes log tree information in a special format. This can be overriden by anybody that uses the library.
All saved files should begin with an unsigned char
version number and an unsigned long long
millisecond timestamp.
unsigned char version
unsigned long long timestamp
Version is representative of both the type of logtree and the format. Versions 0-99
should be indicative of Queues; 100-199
of Statements; 200-255
of Events.
Open event with 0x2
and close with 0x3
. Statements or more events can be written inbetween these tags.
0x2 // open event
// more events or statements
0x3 // close event
Open statement with 0x0
and close 0x1
.
0x0
unsigned long long timestamp
unsigned char verbosity
unsigned char tag_size
unsigned char[] tag
unsigned short message_size
unsigned char[] message
0x1
A close statement tag is always needed in case the serializer method is overriden and provides extra data/metadata. If a close statement tag isn't written, a parser/deserializer won't be able to read a serialized logtree with extra data.
The 6 verbosity level enums and their byte values are:
INFO = 0
DEBUG = 1
VERBOSE = 2
VERYVERBOSE = 3
WARNING = 4
ERROR = 5
1 statement inside one 1 event:
1565561768719 // timestamp 8*
0x2 // open event 1
0x0 // open statement 1
1565561768752 // timestamp 8*
0 // verbosity 1
4 // tag_size 1
"INIT" // tag 4*
5 // message_size 2
"HELLO" // message 5*
0x1 // close statement 1
0x3 // close event 1
// 33 total bytes for this log tree
With the sample log tree used here, the raw byte file totals 25 bytes. In use, a parser/deserializer could take this file and create output similar to the following:
lognestmonster - log_folder/
Size: 33 bytes | Timestamp: 1565561768719
1 Statement | 1 Event | 0 Unsaved Data Trees
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
v 1 ITEM
1565561768752 - INFO - INIT - HELLO
::::::::::: press q to exit | arrow keys to move, expand, collapse :::::::::::
By the nature of a push-write logging library, there's a chance that some created Statements and Events might not be pushed and written before the program's exit, whether it hangs, crashes, throws a runtime exception, is SIGKILLed, or anything else. Seeing as the point of logging is to find and diagnose errors with ease, it'd be frustrating to lose critical last-second information like this. The solution: save temporary serialized data for every creation or change to Statements or Events. Every logtree that ends in a Statement will have its own temporary data file; when a Statement is pushed to an Event, the Statement's file will be deleted and replaced into the greater Event file. See the following example for how data is separated into files:
Queue queue;
Event event;
Statement state1;
Statement state2;
// Existing files:
// statement1.raw
// statement2.raw
event.push(state1)
// Existing files:
// event.raw
// statement2.raw
queue.push(event)
// Existing files:
// event.raw
// statement2.raw
event.push(state2)
// Existing files:
// event.raw (all log items now exist inside the event, in the queue)
queue.write()
// Existing files:
// log12345.raw (consists of 2 statements inside 1 event)
In reality, file names will likely contain timestamps, hashes, UUIDs, or some other form of identifiable metadata.
lognestmonster Copyright (c) 2019 Joshua 'joshuas3' Stockin under the GNU General Public License v3.
The following should be present in each file.
lognestmonster Copyright (c) 2019 Joshua 'joshuas3' Stockin
<https://github.com/JoshuaS3/lognestmonster/>.
This file is part of lognestmonster.
lognestmonster is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
lognestmonster is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with lognestmonster. If not, see <https://www.gnu.org/licenses/>.