Updated file_service

This commit is contained in:
thomashii 2022-03-18 07:57:20 +08:00
parent 174388e075
commit 99cf7790a4
5 changed files with 69 additions and 14 deletions

View file

@ -1,5 +1,13 @@
# Change Log
## 6.0.0
* Updated to min SDK 2.15.x
## 5.0.0
* No release. Skipped
## 4.1.0
* Upgraded to `lints` linter

View file

@ -1,14 +1,27 @@
name: angel3_file_service
version: 4.1.0
version: 6.0.0
description: Angel service that persists data to a file on disk, stored as a JSON list.
homepage: https://angel3-framework.web.app/
repository: https://github.com/dukefirehawk/angel/tree/master/packages/file_service
environment:
sdk: '>=2.12.0 <3.0.0'
dependencies:
angel3_framework: ^4.2.0
angel3_framework: ^6.0.0
file: ^6.1.1
pool: ^1.5.0
dev_dependencies:
test: ^1.17.7
test: ^1.20.0
lints: ^1.0.0
dependency_overrides:
angel3_container:
path: ../container/angel_container
angel3_framework:
path: ../framework
angel3_http_exception:
path: ../http_exception
angel3_model:
path: ../model
angel3_route:
path: ../route
angel3_mock_request:
path: ../mock_request

View file

@ -55,13 +55,23 @@ Future<bool> _defaultErrorHandler(
}
}
/// Default ROOT level logger
Logger _defaultLogger() {
Logger logger = Logger('SERVER')
//..level = Level.WARNING
Logger logger = Logger('ROOT')
..onRecord.listen((rec) {
print(rec);
if (rec.error != null) print(rec.error);
if (rec.stackTrace != null) print(rec.stackTrace);
if (rec.error == null) {
print(rec.message);
}
if (rec.error != null) {
var err = rec.error;
if (err is AngelHttpException && err.statusCode != 500) return;
print('${rec.message} \n');
print(rec.error);
if (rec.stackTrace != null) {
print(rec.stackTrace);
}
}
});
return logger;
@ -120,7 +130,17 @@ class Angel extends Routable {
Angel? get parent => _parent;
/// Outputs diagnostics and debug messages.
Logger logger = _defaultLogger();
Logger _logger = _defaultLogger();
Logger get logger => _logger;
/// Assign a custom logger.
/// Passing null will reset to default logger
set logger(Logger? log) {
_logger.clearListeners();
_logger = log ?? _defaultLogger();
}
/// Plug-ins to be called right before server startup.
///

View file

@ -1,6 +1,7 @@
import 'dart:async';
import 'dart:io';
import 'dart:isolate';
import 'package:intl/intl.dart';
import 'package:angel3_container/angel3_container.dart';
import 'package:angel3_framework/angel3_framework.dart';
import 'package:angel3_framework/http.dart';
@ -54,21 +55,33 @@ _ ___ | /| / / /_/ / _ /___ _ /___
''';
static DateFormat _defaultDateFormat = DateFormat('yyyy-MM-dd HH:mm:ss');
/// LogRecord handler
static void handleLogRecord(LogRecord? record, RunnerOptions options) {
if (options.quiet || record == null) return;
var code = chooseLogColor(record.level);
if (record.error == null) print(code.wrap(record.toString()));
var now = _defaultDateFormat.format(DateTime.now());
if (record.error == null) {
//print(code.wrap(record.message));
print(code.wrap(
'$now ${record.level.name} [${record.loggerName}]: ${record.message}'));
}
if (record.error != null) {
var err = record.error;
if (err is AngelHttpException && err.statusCode != 500) return;
print(code.wrap(record.toString() + '\n'));
print(code.wrap(err.toString()));
//print(code.wrap(record.message + '\n'));
print(code.wrap(
'$now ${record.level.name} [${record.loggerName}]: ${record.message} \n'));
print(code.wrap(
'$now ${record.level.name} [${record.loggerName}]: ${err.toString()}'));
if (record.stackTrace != null) {
print(code.wrap(record.stackTrace.toString()));
print(code.wrap(
'$now ${record.level.name} [${record.loggerName}]: ${record.stackTrace.toString()}'));
}
}
}
@ -220,7 +233,7 @@ _ ___ | /| / / /_/ / _ /___ _ /___
/// Run with main isolate
static void isolateMain(_RunnerArgsWithId argsWithId) {
var args = argsWithId.args;
hierarchicalLoggingEnabled = true;
hierarchicalLoggingEnabled = false;
var zone = Zone.current.fork(specification: ZoneSpecification(
print: (self, parent, zone, msg) {

View file

@ -12,6 +12,7 @@ dependencies:
args: ^2.3.0
io: ^1.0.0
logging: ^1.0.1
intl: ^0.17.0
dev_dependencies:
lints: ^1.0.1
dependency_overrides: