getJsonString method
Converts the log message to a JSON string.
first: If true, omits the leading comma and newline (for the first entry in a list).
Returns: A JSON-encoded string representing the log message.
Implementation
String getJsonString(bool first) {
final Map<String, dynamic> data = {
'level': level.toString().split('.').last,
'category': category,
'message': message,
'environment': environment,
'timeStamp': timeStamp?.toIso8601String() ?? DateTime.now(),
'timeLine': timeLine,
};
if (!first) {
return ',\n${jsonEncode(data)}';
}
return jsonEncode(data);
}