Pub

About

Cross-platform html/io [L]ogger with simple API.
No need to create an logger object. Just import and use. Simple and w/o boilerplate.
Work with native console and can store logs in txt files (io) and indexedDB (web).
You can change verbose level and resume/pause log queue, also you can clear console.


Core API

Key features
MethodDescription
sA shout is always displayed
vRegular message with verbose level 1
eError message with verbose level 1
vvRegular message with verbose level 2
wWarning message with verbose level 2
vvvRegular message with verbose level 3
i or <Inform message with verbose level 3
vvvvRegular message with verbose level 4
d or <<Debug message with verbose level 4
vvvvvRegular message with verbose level 5
vvvvvvRegular message with verbose level 6
l.s('shout me');
l.e('error msg');
l.w('warning msg');
l.i('info msg');
l < 'alt info msg';
l.d('debug msg');
l << 'alt debug msg';
l.v('verbose lvl #1');
l.vv('verbose lvl #2');
l.vvv('verbose lvl #3');
l.vvvv('verbose lvl #4');
l.vvvvv('verbose lvl #5');
l.vvvvvv('verbose lvl #6');
~l;
Setup and management
MethodDescription
lvlLimiting output level (default 3 in release, 6 in debug)
storeSet to true to save logs (default is false)
wideDisplay wide prefix entry (default is false)
pausePause for message queue
resumeContinued after a pause
clearConsole cleaning (if a terminal is connected)
l.lvl = 4;
l.store = true;
l.wide = false;
l.pause();
l.resume();
l.clear();
Progress

Only works in io environments with a connected terminal.
If it is impossible to output - ignored.
Pauses the output of the remaining logs, do not forget to use the "resume".

MethodDescription
pDisplays a progress bar
resumeContinued after progress finished
Stream<int>.fromIterable(List<int>.generate(101, (int v) => v))
    .asyncMap<int>((int v) =>
        Future<int>.delayed(const Duration(milliseconds: 25), () => v))
    .forEach((int v) => l.p(
        percent: v,
        header: '{{ HEADER $v }}',
        data: '{{ data $v% }}',
        footer: '{{ footer $v }}',))
      ..whenComplete(l.resume); // Must use 'resume'

Output:

                {{ HEADER 21 }}
[========>       {{ data 21% }}                ]
                                {{ footer 21 }}
Integration capabilities
MethodDescription
streamBroadcast stream instantly receiving logs.
mwMiddleware queue with functions
// Broadcast stream instantly receiving logs.
l.stream.forEach((LogMessage log) => print('* ${log.level}'));

// Middleware queue, functions are called 
// at the time of log processing
// and block further until complete execution
l.mw.addAll(<Future<void> Function(LogMessage)>[
  (LogMessage log) async {print('# ${log.date}');},
  (LogMessage log) async {print('# ${log.message}');},
]);

Limitations

  • When there is no direct access to the terminal, it works through print.
  • When it is not possible to get write access to the working directory, the logs are not saved.
  • Do not log sensitive information.

License

MIT


Tags

logger, log, logs, logging, logging-library, cross-platform, io, html

Libraries

l
Logger library [...]