htmlReport method

Future<String> htmlReport()

Implementation

Future<String> htmlReport() async {
  String res = '''
    <html>
      <style>
        * { font-family: "Courier New", Courier, monospace"; }
        .f { background-color: #c70000; color: white}
        .e { background-color: #7d0a0a; color: white}
        .w { background-color: #7d3f0a; color: white}
        .i { background-color: #353535; color: white}
        .d { background-color: #353535; color: #c5c5c5}
        .t { background-color: #353535; color: #848484}
      </style>
    <body>''';

  res +='<h1>App report ${await getPackageInfo()}</h1>';

  res += '<table>';
  _LogHistory.instance.messages.forEach((entry) {
    var levelClass = 't';
    switch(entry.level) {
      case _LEVELS.FATAL: levelClass = 'f'; break;
      case _LEVELS.ERROR: levelClass = 'e'; break;
      case _LEVELS.WARN:  levelClass = 'w'; break;
      case _LEVELS.INFO:  levelClass = 'i'; break;
      case _LEVELS.DEBUG: levelClass = 'd'; break;
      case _LEVELS.TRACE: levelClass = 't'; break;
    }

    res += '<tr><td class="$levelClass">';
    res += "${entry.message.replaceAll('<', '&lt;').replaceAll('>', '&gt;')}";
    res += '</td></tr>';
  });

  res += '</table></body></html>';

  return res;

}