Skip to content

Commit

Permalink
chore: add readme instructions for using the logLevel property
Browse files Browse the repository at this point in the history
  • Loading branch information
bruuuuuuuce committed Dec 19, 2023
1 parent e3bc173 commit 47ce4df
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
19 changes: 13 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,20 @@ const like = 'sample';

## Logging

We use the [Dart logging package](https://github.com/dart-lang/logging) to create internal Loggers for producing Momento-related logs. The default logger does not do anything with the logs, so you must configure the logging level and handler at the beginning of your program:
There is a `LogLevel` enum that contains the following log levels:

```
Logger.root.level = Level.ALL; // defaults to Level.INFO
Logger.root.onRecord.listen((record) {
print('${record.level.name}: ${record.time}: ${record.message}');
});
* `LogLevel.trace`
* `LogLevel.debug`
* `LogLevel.info`
* `LogLevel.warn`
* `LogLevel.error`
* `LogLevel.fatal`
* `LogLevel.off`

This enum can be used to configure the logging level of the Momento package. By default, the logging level is set to `LogLevel.info`. To change the logging level, pass the desired level to the `Configuration` constructor:

```dart
var config = Mobile.latest(logLevel: LogLevel.debug);
```

## Additional information
Expand Down
2 changes: 1 addition & 1 deletion lib/src/config/cache_configurations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Mobile extends CacheClientConfigurations {
return latest();
}

static CacheClientConfiguration latest({logLevel = LogLevel.info}) {
static CacheClientConfiguration latest({LogLevel logLevel = LogLevel.info}) {
return CacheClientConfiguration(
StaticTransportStrategy(StaticGrpcConfiguration(Duration(seconds: 15))),
logLevel);
Expand Down
3 changes: 3 additions & 0 deletions lib/src/config/logger.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ enum LogLevel {
warn,
error,
fatal,
off,
}

Level determineLoggerLevel(LogLevel logLevel) {
Expand All @@ -23,5 +24,7 @@ Level determineLoggerLevel(LogLevel logLevel) {
return Level.SEVERE;
case LogLevel.fatal:
return Level.SHOUT;
case LogLevel.off:
return Level.OFF;
}
}

0 comments on commit 47ce4df

Please sign in to comment.