1.7 KiB
IDLs and BlogIDL; Part One.md
You might have noticed the language used in my blog post is not any other existing language.
It is what is called an IDL or Interface Definition Language. Typically IDLs are used to define interchange formats for programs, like I use it for.
These languages are used to define how data is laid out in byte format.
In this post I will be explaining and defining a log format.
Typical logging systems have multiple severities of logs.
The log crate for rust operates using five different log levels
Error
Warn
Info
Debug
Trace
The winston library for javascript uses the following levels.
error
warn
info
http
verbose
debug
silly
There is also this RFC which I won't read
I am partial to the log
method so let us adopt that format for log levels.
We should also assign a numerical value to each log level starting with the most important to the least important.
enum LogLevel {
Error = 0,
Warn = 1,
Info = 2,
Debug = 3,
Trace = 4,
}
Thats a bit much and adding a new level is not an automatic increment thing.
Lets introduce a new concept to the language called an attribute.
@auto_increment
enum LogLevel {
Error = 0,
Warn,
Info,
Debug,
Trace,
}
The auto_increment
attribute finds all enum variants with a number and increments by one whole number until it finds an already assigned number or there are no more variants.
This reduces the chance of messing up aswell as makes you just type less. Syntax sugar and all that.