-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add log level to prebuilt configurations (#33)
- Loading branch information
1 parent
b79d671
commit 7d7275d
Showing
8 changed files
with
96 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,47 @@ | ||
import 'package:client_sdk_dart/src/config/transport/grpc_configuration.dart'; | ||
import 'package:client_sdk_dart/src/config/transport/transport_strategy.dart'; | ||
|
||
import '../../client_sdk_dart.dart'; | ||
|
||
abstract interface class CacheConfiguration { | ||
/// Configures low-level options for network interactions with the Momento service | ||
late TransportStrategy transportStrategy; | ||
|
||
/// Configures the verbosity of the client-side logger | ||
LogLevel logLevel; | ||
|
||
/// Constructor for a CacheConfiguration | ||
CacheConfiguration(this.transportStrategy); | ||
CacheConfiguration(this.transportStrategy, this.logLevel); | ||
|
||
/// Copy constructor for overriding TransportStrategy | ||
CacheConfiguration withTransportStrategy(TransportStrategy transportStrategy); | ||
CacheConfiguration withTransportStrategy(TransportStrategy transportStrategy, | ||
{LogLevel logLevel = LogLevel.info}); | ||
|
||
/// Convenience copy constructor that updates the client-side | ||
/// timeout setting in the transport strategy | ||
CacheConfiguration withDeadline(Duration deadline); | ||
CacheConfiguration withDeadline(Duration deadline, | ||
{LogLevel logLevel = LogLevel.info}); | ||
} | ||
|
||
class CacheClientConfiguration implements CacheConfiguration { | ||
@override | ||
late TransportStrategy transportStrategy; | ||
|
||
CacheClientConfiguration(this.transportStrategy); | ||
@override | ||
LogLevel logLevel; | ||
|
||
CacheClientConfiguration(this.transportStrategy, this.logLevel); | ||
|
||
@override | ||
CacheConfiguration withTransportStrategy( | ||
TransportStrategy transportStrategy) { | ||
return CacheClientConfiguration(transportStrategy); | ||
CacheConfiguration withTransportStrategy(TransportStrategy transportStrategy, | ||
{LogLevel logLevel = LogLevel.info}) { | ||
return CacheClientConfiguration(transportStrategy, logLevel); | ||
} | ||
|
||
@override | ||
CacheConfiguration withDeadline(Duration deadline) { | ||
CacheConfiguration withDeadline(Duration deadline, | ||
{LogLevel logLevel = LogLevel.info}) { | ||
return CacheClientConfiguration( | ||
StaticTransportStrategy(StaticGrpcConfiguration(deadline))); | ||
StaticTransportStrategy(StaticGrpcConfiguration(deadline)), logLevel); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import 'package:logging/logging.dart'; | ||
|
||
enum LogLevel { | ||
trace, | ||
debug, | ||
info, | ||
warn, | ||
error, | ||
fatal, | ||
off, | ||
} | ||
|
||
Level determineLoggerLevel(LogLevel logLevel) { | ||
switch (logLevel) { | ||
case LogLevel.trace: | ||
return Level.ALL; | ||
case LogLevel.debug: | ||
return Level.FINE; | ||
case LogLevel.info: | ||
return Level.INFO; | ||
case LogLevel.warn: | ||
return Level.WARNING; | ||
case LogLevel.error: | ||
return Level.SEVERE; | ||
case LogLevel.fatal: | ||
return Level.SHOUT; | ||
case LogLevel.off: | ||
return Level.OFF; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters