Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

logzio: remove 'time', 'level' and 'loggerName' from 'message' #6

Open
deezaster opened this issue Mar 25, 2020 · 1 comment
Open

Comments

@deezaster
Copy link

the fields 'time', 'level' and 'loggerName' are already sent individually to logz.io. Therefore they are not needed in 'message'.

sb.write('${rec.time} ${rec.level.name} ${rec.loggerName} - ${rec.message}');
@chadpav
Copy link

chadpav commented Jan 25, 2024

You have control over the log formatter by overriding the default one.

Here is how I initialize LogzIoApiAppender:

final logzIoApiSender = LogzIoApiAppender(
      formatter: BlockFormatter.formatRecord(_logFormatter),
      apiToken: _logzIoToken,
      labels: {
        'os': Platform.operatingSystem,
        'os_version': Platform.operatingSystemVersion,
        'locale': Platform.localeName,
        'build_mode': kDebugMode ? 'debug' : 'release',
      },
      type: 'flutter',
    );

and that BlockFormatter.formatRecord(_logFormatter) is taking a private function which can be defined as whatever you need. Here is what I'm using:

String _logFormatter(LogRecord rec) {
    final sb = StringBuffer();
    sb.write('${rec.level.name} - ${rec.message}');
    if (rec.error != null) {
      sb.writeln();
      sb.write('### ${rec.error?.runtimeType}: ');
      sb.write(rec.error);
    }
    // ignore: avoid_as
    final stackTrace = rec.stackTrace ?? (rec.error is Error ? (rec.error as Error).stackTrace : null);
    if (stackTrace != null) {
      sb.writeln();
      sb.write(stackTrace);
    }
    return sb.toString();
  }

Is this what you needed? Doh, just realized this is a really old issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants