mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-28 09:47:35 +08:00
Logging: Allow logging structured fields
Display this in the Debug Screen app. Additionally, add a reason why a file was not loaded.
This commit is contained in:
@ -186,12 +186,15 @@ class NotesFolderFS with NotesFolderNotifier implements NotesFolder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (fsEntity is Directory) {
|
if (fsEntity is Directory) {
|
||||||
Log.v("Found directory ${fsEntity.path}");
|
|
||||||
var subFolder = NotesFolderFS(this, fsEntity.path);
|
var subFolder = NotesFolderFS(this, fsEntity.path);
|
||||||
if (subFolder.name.startsWith('.')) {
|
if (subFolder.name.startsWith('.')) {
|
||||||
|
Log.v("Ignoring Folder", props: {
|
||||||
|
"path": fsEntity.path,
|
||||||
|
"reason": "Hidden folder",
|
||||||
|
});
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
Log.v("Found folder ${fsEntity.path}");
|
Log.v("Found Folder", props: {"path": fsEntity.path});
|
||||||
_addFolderListeners(subFolder);
|
_addFolderListeners(subFolder);
|
||||||
|
|
||||||
_folders.add(subFolder);
|
_folders.add(subFolder);
|
||||||
@ -203,11 +206,21 @@ class NotesFolderFS with NotesFolderNotifier implements NotesFolder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var note = Note(this, fsEntity.path);
|
var note = Note(this, fsEntity.path);
|
||||||
if (!note.filePath.toLowerCase().endsWith('.md')) {
|
if (note.fileName.startsWith('.')) {
|
||||||
Log.v("Ignoring file ${fsEntity.path}");
|
Log.v("Ignoring file", props: {
|
||||||
|
"path": fsEntity.path,
|
||||||
|
"reason": "Starts with a .",
|
||||||
|
});
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
Log.v("Found file ${fsEntity.path}");
|
if (!note.filePath.toLowerCase().endsWith('.md')) {
|
||||||
|
Log.v("Ignoring file", props: {
|
||||||
|
"path": fsEntity.path,
|
||||||
|
"reason": "Doesn't end with a .md",
|
||||||
|
});
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Log.v("Found file", props: {"path": fsEntity.path});
|
||||||
_addNoteListeners(note);
|
_addNoteListeners(note);
|
||||||
|
|
||||||
_notes.add(note);
|
_notes.add(note);
|
||||||
|
@ -79,12 +79,33 @@ class _DebugScreenState extends State<DebugScreen> {
|
|||||||
if (msg.stack != null) {
|
if (msg.stack != null) {
|
||||||
str += ' ' + msg.stack;
|
str += ' ' + msg.stack;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var props = <TextSpan>[];
|
||||||
|
msg.props?.forEach((key, value) {
|
||||||
|
var emptySpace = TextSpan(
|
||||||
|
text: '\n ',
|
||||||
|
style: textStyle.copyWith(fontWeight: FontWeight.bold));
|
||||||
|
props.add(emptySpace);
|
||||||
|
|
||||||
|
var keySpan = TextSpan(
|
||||||
|
text: '$key: ',
|
||||||
|
style: textStyle.copyWith(
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
var valueSpan = TextSpan(text: value.toString());
|
||||||
|
|
||||||
|
props.add(keySpan);
|
||||||
|
props.add(valueSpan);
|
||||||
|
});
|
||||||
|
|
||||||
return RichText(
|
return RichText(
|
||||||
text: TextSpan(children: [
|
text: TextSpan(children: [
|
||||||
TextSpan(
|
TextSpan(
|
||||||
text: timeStr,
|
text: timeStr,
|
||||||
style: textStyle.copyWith(fontWeight: FontWeight.bold)),
|
style: textStyle.copyWith(fontWeight: FontWeight.bold)),
|
||||||
TextSpan(text: str),
|
TextSpan(text: str),
|
||||||
|
...props,
|
||||||
], style: textStyle),
|
], style: textStyle),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -29,29 +29,34 @@ class Log {
|
|||||||
await setLogCapture(true);
|
await setLogCapture(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void v(String msg, {dynamic ex, StackTrace stacktrace}) {
|
static void v(String msg,
|
||||||
|
{dynamic ex, StackTrace stacktrace, Map<String, dynamic> props}) {
|
||||||
Fimber.v(msg, ex: ex, stacktrace: stacktrace);
|
Fimber.v(msg, ex: ex, stacktrace: stacktrace);
|
||||||
_write('v', msg, ex, stacktrace);
|
_write('v', msg, ex, stacktrace, props);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void d(String msg, {dynamic ex, StackTrace stacktrace}) {
|
static void d(String msg,
|
||||||
|
{dynamic ex, StackTrace stacktrace, Map<String, dynamic> props}) {
|
||||||
Fimber.d(msg, ex: ex, stacktrace: stacktrace);
|
Fimber.d(msg, ex: ex, stacktrace: stacktrace);
|
||||||
_write('d', msg, ex, stacktrace);
|
_write('d', msg, ex, stacktrace, props);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void i(String msg, {dynamic ex, StackTrace stacktrace}) {
|
static void i(String msg,
|
||||||
|
{dynamic ex, StackTrace stacktrace, Map<String, dynamic> props}) {
|
||||||
Fimber.i(msg, ex: ex, stacktrace: stacktrace);
|
Fimber.i(msg, ex: ex, stacktrace: stacktrace);
|
||||||
_write('i', msg, ex, stacktrace);
|
_write('i', msg, ex, stacktrace, props);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void e(String msg, {dynamic ex, StackTrace stacktrace}) {
|
static void e(String msg,
|
||||||
|
{dynamic ex, StackTrace stacktrace, Map<String, dynamic> props}) {
|
||||||
Fimber.e(msg, ex: ex, stacktrace: stacktrace);
|
Fimber.e(msg, ex: ex, stacktrace: stacktrace);
|
||||||
_write('e', msg, ex, stacktrace);
|
_write('e', msg, ex, stacktrace, props);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void w(String msg, {dynamic ex, StackTrace stacktrace}) {
|
static void w(String msg,
|
||||||
|
{dynamic ex, StackTrace stacktrace, Map<String, dynamic> props}) {
|
||||||
Fimber.w(msg, ex: ex, stacktrace: stacktrace);
|
Fimber.w(msg, ex: ex, stacktrace: stacktrace);
|
||||||
_write('w', msg, ex, stacktrace);
|
_write('w', msg, ex, stacktrace, props);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _write(
|
static void _write(
|
||||||
@ -59,6 +64,7 @@ class Log {
|
|||||||
String msg,
|
String msg,
|
||||||
dynamic ex,
|
dynamic ex,
|
||||||
StackTrace stackTrace,
|
StackTrace stackTrace,
|
||||||
|
Map<String, dynamic> props,
|
||||||
) {
|
) {
|
||||||
if (logFile == null) {
|
if (logFile == null) {
|
||||||
return;
|
return;
|
||||||
@ -72,6 +78,7 @@ class Log {
|
|||||||
stack: stackTrace != null
|
stack: stackTrace != null
|
||||||
? stackTrace.toString().replaceAll('\n', ' ')
|
? stackTrace.toString().replaceAll('\n', ' ')
|
||||||
: null,
|
: null,
|
||||||
|
props: props,
|
||||||
);
|
);
|
||||||
|
|
||||||
var str = json.encode(logMsg.toMap());
|
var str = json.encode(logMsg.toMap());
|
||||||
@ -118,6 +125,7 @@ class LogMessage {
|
|||||||
String msg;
|
String msg;
|
||||||
String ex;
|
String ex;
|
||||||
String stack;
|
String stack;
|
||||||
|
Map<String, dynamic> props;
|
||||||
|
|
||||||
LogMessage({
|
LogMessage({
|
||||||
@required this.t,
|
@required this.t,
|
||||||
@ -125,6 +133,7 @@ class LogMessage {
|
|||||||
@required this.msg,
|
@required this.msg,
|
||||||
this.ex,
|
this.ex,
|
||||||
this.stack,
|
this.stack,
|
||||||
|
this.props,
|
||||||
});
|
});
|
||||||
|
|
||||||
Map<String, dynamic> toMap() {
|
Map<String, dynamic> toMap() {
|
||||||
@ -134,6 +143,7 @@ class LogMessage {
|
|||||||
'msg': msg,
|
'msg': msg,
|
||||||
if (ex != null && ex.isNotEmpty) 'ex': ex,
|
if (ex != null && ex.isNotEmpty) 'ex': ex,
|
||||||
if (stack != null && stack.isNotEmpty) 'stack': stack,
|
if (stack != null && stack.isNotEmpty) 'stack': stack,
|
||||||
|
if (props != null && props.isNotEmpty) 'p': props,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -143,5 +153,6 @@ class LogMessage {
|
|||||||
msg = map['msg'];
|
msg = map['msg'];
|
||||||
ex = map['ex'];
|
ex = map['ex'];
|
||||||
stack = map['stack'];
|
stack = map['stack'];
|
||||||
|
props = map['p'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user