Skip to content

fpessolano/mlogger

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MLOGGER

About: module for multi file level logging
Author: F.Pessolano
Licence: MIT

NO LONGER SUPPORTED

Description
Module for implementing centralised level loggers with multiple files and aggregation of log lines.
Each log line follows this format:

DATE_LINE_CREATION    ID  LEVEL   MESSAGE DATA    DATE_LAST_CHANGE

The mlogger module supports as level LOG, INFO, ERROR, WARNING, RECOVERED amd PANIC. Apart from the traditional message, data can be included in the log line and it can be accumulated over time (in this case the last update date is also added as of the first accumulation). Log files are stored in the folder ./log/

Initialisation
A logger is initialised with:

logId, er := mlogger.DeclareLog(name, date) 

Where name is the logfile name. A log file is created everyday and the date appended to the name if date is true.
An id is given in logId (int) and an er error returned if any.
The logfile is formatted with the methods:

mlogger.SetTextLimit(logId, lm, li, ll)

Where lm, li and ll are the number of maximum characters to be used for the message text, id and level. If 0 is given, no restriction will be used. The logs can also be set to echo all written liones to the console by togglingthe verbose flag:

mlogger.Verbose({true|false})

Usage A log line can be stored by using a method associated to a given level (Log, Info, Error, Warning, Recovered amd Panic). For example:

mlogger.Log(logId, LoggerData{Id: string, Message: string, Data: []int, Agregate: bool})  

LoggerData is a struct containing the log line data. When Aggregate is true, the data in Data will be summed and the old first written log line will be updated with the new value and the latest modification date.
The mlogger.Panic level method accept an additional parameter:

mlogger.Panic(logId, LoggerData{Id: id, Message: message, Data: data, Agregate: aggregate}, quit)  

Quit is a bool. When set, it will force the execution to brutally halt.