Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/app/view/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class _AppState extends State<App> {

final featureAccess = context.watch<FeatureAccess>();

context.read<AppLogger>().applyConfig(featureAccess.loggingConfig.logLevel);
context.read<AppLogger>().applyConfig(featureAccess.loggingConfig);

final initialTabResolver = BottomMenuInitialTabResolver(
config: featureAccess.bottomMenuConfig,
Expand Down
4 changes: 2 additions & 2 deletions lib/bootstrap.dart
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ Future<InstanceRegistry> bootstrap() async {

// Logger
final appLogger = await AppLogger.init(
featureAccess.loggingConfig.logLevel,
featureAccess.loggingConfig,
LogzioLoggingService.fromEnvironment(featureAccess.loggingConfig.remoteLoggingEnabled),
appLabels,
);
Expand Down Expand Up @@ -285,7 +285,7 @@ Future<void> _handleBackgroundMessage(RemoteMessage message, Logger logger) asyn
final overrides = FeatureOverridesFactory.create(remoteCacheConfigService.snapshot);
final loggingConfig = LoggingMapper.mapFromOverridesOnly(overrides);
await AppLogger.init(
loggingConfig.logLevel,
loggingConfig,
LogzioLoggingService.fromEnvironment(loggingConfig.remoteLoggingEnabled),
appLabelsProvider,
);
Expand Down
2 changes: 1 addition & 1 deletion lib/common/logging/anonymizing_formatter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ enum AnonymizationType {
}

class AnonymizingFormatter extends ColorFormatter {
final List<AnonymizationType> anonymizationTypes;
List<AnonymizationType> anonymizationTypes;

AnonymizingFormatter({
LogRecordFormatter wrappedFormatter = const DefaultLogRecordFormatter(),
Expand Down
10 changes: 8 additions & 2 deletions lib/common/logging/logzio_logging_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,18 @@ class LogzioLoggingService implements RemoteLoggingService {

FilteredLogzIoAppender? _filteredLogzIoAppender;

AnonymizingFormatter? _remoteFormatter;

@override
void initialize(Map<String, String> labels) {
_logger.finest('Initializing with url: $url, token: $token, bufferSize: $bufferSize labels: $labels');
final remoteFormatter = AnonymizingFormatter(
_remoteFormatter = AnonymizingFormatter(
anonymizationTypes: AnonymizationType.full,
wrappedFormatter: const RemoteFormatter(),
);

_filteredLogzIoAppender = FilteredLogzIoAppender(
formatter: remoteFormatter,
formatter: _remoteFormatter!,
url: url,
apiToken: token,
bufferSize: bufferSize,
Expand All @@ -54,6 +56,10 @@ class LogzioLoggingService implements RemoteLoggingService {
)..attachToLogger(Logger.root);
}

void setAnonymizationEnabled(bool enabled) {
_remoteFormatter?.anonymizationTypes = enabled ? AnonymizationType.full : [];
}

@override
void dispose() {
_filteredLogzIoAppender?.dispose();
Expand Down
14 changes: 8 additions & 6 deletions lib/data/app_logger.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ import 'package:webtrit_callkeep/webtrit_callkeep.dart';

import 'package:webtrit_phone/common/common.dart';

import '../models/feature_access/logging_config.dart';
import 'app_metadata_provider.dart';

final _logger = Logger('AppLogger');

class AppLogger {
static Future<AppLogger> init(
Level logLevel,
LoggingConfig config,
LogzioLoggingService? logzioService,
AppMetadataProvider labelsProvider,
) async {
Expand All @@ -27,7 +28,7 @@ class AppLogger {
logzioService?.initialize(labelsProvider.logLabels);

final instance = AppLogger._(logzioService, labelsProvider);
instance.applyConfig(logLevel);
instance.applyConfig(config);

return instance;
}
Expand All @@ -37,10 +38,11 @@ class AppLogger {
final LogzioLoggingService? _logzioService;
final AppMetadataProvider _labelsProvider;

void applyConfig(Level logLevel) {
Logger.root.level = logLevel;
EquatableConfig.stringify = logLevel <= Level.FINE || (_logzioService?.minLevel ?? Level.OFF) <= Level.FINE;
_logger.info('AppLogger log level applied: $logLevel');
void applyConfig(LoggingConfig config) {
Logger.root.level = config.logLevel;
_logzioService?.setAnonymizationEnabled(config.anonymizationEnabled);
EquatableConfig.stringify = config.logLevel <= Level.FINE || (_logzioService?.minLevel ?? Level.OFF) <= Level.FINE;
_logger.info('AppLogger log level applied: ${config.logLevel}');
}

/// Allows regenerating labels when coreUrl and tenantId are available.
Expand Down
2 changes: 2 additions & 0 deletions lib/data/feature_access.dart
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,7 @@ abstract final class LoggingMapper {
logLevel: logLevel,
monitorCheckInterval: monitorCheckInterval,
remoteLoggingEnabled: overrides.remoteLoggingEnabled ?? _defaultRemoteLoggingEnabled,
anonymizationEnabled: overrides.isLogAnonymizationEnabled ?? loggingFeature?.anonymizationEnabled ?? true,
);
}

Expand All @@ -621,6 +622,7 @@ abstract final class LoggingMapper {
logLevel: overrides.logLevel ?? _defaultLogLevel,
monitorCheckInterval: overrides.monitorCheckInterval ?? _defaultInterval,
remoteLoggingEnabled: overrides.remoteLoggingEnabled ?? _defaultRemoteLoggingEnabled,
anonymizationEnabled: overrides.isLogAnonymizationEnabled ?? true,
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/features/call/services/services_isolate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Future<void> _initializeCommonDependencies() async {
final isolateOverrides = FeatureOverridesFactory.create(_remoteConfigService!.snapshot);
final isolateLoggingConfig = LoggingMapper.mapFromOverridesOnly(isolateOverrides);
_appLogger ??= await AppLogger.init(
isolateLoggingConfig.logLevel,
isolateLoggingConfig,
LogzioLoggingService.fromEnvironment(isolateLoggingConfig.remoteLoggingEnabled),
_appLabelsProvider!,
);
Expand Down
4 changes: 4 additions & 0 deletions lib/models/feature_access/feature_overrides.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class FeatureOverrides extends Equatable {
this.monitorCheckInterval,
this.logLevel,
this.remoteLoggingEnabled,
this.isLogAnonymizationEnabled,
});

final bool? isVideoCallEnabled;
Expand All @@ -21,6 +22,7 @@ class FeatureOverrides extends Equatable {
final Duration? monitorCheckInterval;
final Level? logLevel;
final bool? remoteLoggingEnabled;
final bool? isLogAnonymizationEnabled;

@override
List<Object?> get props => [
Expand All @@ -42,6 +44,7 @@ abstract final class FeatureOverridesFactory {
static const _kMonitorCheckIntervalKey = 'feature_monitor_check_interval_sec';
static const _kLogLevelKey = 'feature_log_level';
static const _kRemoteLoggingEnabledKey = 'firebaseRemoteLogging';
static const _kLogAnonymizationEnabledKey = 'feature_log_anonymization_enabled';

static FeatureOverrides create(RemoteConfigSnapshot snapshot) {
final monitorIntervalSec = int.tryParse(snapshot.getString(_kMonitorCheckIntervalKey) ?? '');
Expand All @@ -61,6 +64,7 @@ abstract final class FeatureOverridesFactory {
monitorCheckInterval: monitorCheckInterval,
logLevel: logLevel,
remoteLoggingEnabled: snapshot.getBool(_kRemoteLoggingEnabledKey),
isLogAnonymizationEnabled: snapshot.getBool(_kLogAnonymizationEnabledKey),
);
}
}
10 changes: 8 additions & 2 deletions lib/models/feature_access/logging_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@ import 'package:equatable/equatable.dart';
import 'package:logging/logging.dart';

class LoggingConfig extends Equatable {
const LoggingConfig({required this.logLevel, required this.monitorCheckInterval, required this.remoteLoggingEnabled});
const LoggingConfig({
required this.logLevel,
required this.monitorCheckInterval,
required this.remoteLoggingEnabled,
required this.anonymizationEnabled,
});

final Level logLevel;
final Duration monitorCheckInterval;
final bool remoteLoggingEnabled;
final bool anonymizationEnabled;

@override
List<Object?> get props => [logLevel, monitorCheckInterval, remoteLoggingEnabled];
List<Object?> get props => [logLevel, monitorCheckInterval, remoteLoggingEnabled, anonymizationEnabled];
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@ sealed class SupportedFeature with _$SupportedFeature {
/// [logLevel] controls the application log level. Defaults to 'INFO'.
/// [checkIntervalSec] defines how often the [RtpTrafficMonitor] checks for traffic.
/// Defaults to 15 seconds.
const factory SupportedFeature.loggingConfig({@Default('INFO') String logLevel, @Default(15) int checkIntervalSec}) =
SupportedLoggingConfig;
const factory SupportedFeature.loggingConfig({
@Default('INFO') String logLevel,
@Default(15) int checkIntervalSec,
@Default(true) bool anonymizationEnabled,
}) = SupportedLoggingConfig;

const factory SupportedFeature.systemNotifications({@Default(true) bool enabled}) = SupportedSystemNotifications;

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading