logging_collector

Last updated:

0 purchases

logging_collector Image
logging_collector Images
Add to Cart

Description:

logging collector

logging_collector #
Simple package for logging in files and logs sharing.
Setup logging directory
import 'package:path_provider/path_provider.dart';

final Directory docsDirectory = await getApplicationDocumentsDirectory();

final logsDirectoryPath = '${docsDirectory.path}/logs';
final logsDirectory = Directory(logsDirectoryPath);
logsDirectory.createSync();
copied to clipboard
create RollingFileAppender, it'll write log messages into logs directory
import 'package:logging_collector/logging_collector.dart';
final appenders = [
RollingFileAppender(
directoryPath: logsDirectoryPath,
fileMaxSize: 1024 * 1024,
fileMaxCount: 3,
),
];
copied to clipboard
use RollingFileAppender for logging
import 'package:logging/logging.dart';

Logger.root.onRecord.listen(
(LogRecord record) async {
String log = record.message;

for (final appender in appenders) {
await appender.append(log);
}
},
);
copied to clipboard
create LoggingCollectorConfig and run app
import 'package:logging_collector/logging_collector.dart';
final loggingCollectorConfig = LoggingCollectorConfig(
logsDirectoryPath,
_CustomSharingDelegate(logsDirectory),
);

runApp(
Provider<LoggingCollectorConfig>.value(
value: loggingCollectorConfig,
child: const MyApp(),
),
);
copied to clipboard
For logs monitoring, sharing and clearing logs forlder you can use LoggingCollectorWidget
For logs sharing (optional) you can implement LogsSharingDelegate. E.g.
import 'package:archive/archive_io.dart';
class _CustomSharingDelegate implements LogsSharingDelegate {
final Directory _logsDirectory;

_CustomSharingDelegate(this._logsDirectory);

@override
Future<void> share() async {
final zipEncoder = ZipFileEncoder();
final zipPath = '../${_logsDirectory.path}/logs.zip';
zipEncoder.zipDirectory(
_logsDirectory,
filename: zipPath,
);

Share.shareXFiles(
[XFile(zipPath)],
subject: 'Share',
text: 'Share logs',
);
}
}
copied to clipboard

License:

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.