Skip to content

Commit 6cd8645

Browse files
committed
readme updates for logging
1 parent bfab253 commit 6cd8645

File tree

2 files changed

+74
-6
lines changed

2 files changed

+74
-6
lines changed

README.md

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ String datafileContent = "..." // ... load your datafile content
128128
DatafileContent datafile = DatafileContent.fromJson(datafileContent);
129129

130130
// Create SDK instance
131-
Instance instance = new Instance(
131+
Instance f = new Instance(
132132
new Instance.InstanceOptions()
133133
.datafile(datafileContent)
134134
);
@@ -443,13 +443,30 @@ f.setLogLevel(Logger.LogLevel.DEBUG);
443443
You can also pass your own log handler, if you do not wish to print the logs to the console:
444444

445445
```java
446-
Instance f = Featurevisor.createInstance(new Instance.InstanceOptions()
447-
.datafile(datafile)
448-
.logLevel(Logger.LogLevel.INFO)
449-
.logHandler((level, message, details) -> {
446+
// Create a custom logger with a custom handler
447+
Logger customLogger = Logger.createLogger(new Logger.CreateLoggerOptions()
448+
.level(Logger.LogLevel.INFO)
449+
.handler((level, message, details) -> {
450450
// do something with the log
451451
System.out.println("[" + level + "] " + message);
452452
}));
453+
454+
Instance f = Featurevisor.createInstance(new Instance.InstanceOptions()
455+
.datafile(datafile)
456+
.logger(customLogger));
457+
```
458+
459+
Alternatively, you can create a custom logger directly:
460+
461+
```java
462+
Logger customLogger = new Logger(Logger.LogLevel.INFO, (level, message, details) -> {
463+
// do something with the log
464+
System.out.println("[" + level + "] " + message);
465+
});
466+
467+
Instance f = Featurevisor.createInstance(new Instance.InstanceOptions()
468+
.datafile(datafile)
469+
.logger(customLogger));
453470
```
454471

455472
Further log levels like `info` and `debug` will help you understand how the feature variations and variables are evaluated in the runtime against given context.

src/main/java/com/featurevisor/sdk/Instance.java

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,57 @@ public Map<String, Object> getAllEvaluations(Map<String, Object> context) {
675675
}
676676

677677
public Map<String, Object> getAllEvaluations() {
678-
return getAllEvaluations(null, null, null);
678+
return getAllEvaluations(getContext());
679+
}
680+
681+
// Static factory methods for direct function-like access
682+
/**
683+
* Create a new Featurevisor instance with default options
684+
* @return new Instance
685+
*/
686+
public static Instance createInstance() {
687+
return new Instance(new InstanceOptions());
688+
}
689+
690+
/**
691+
* Create a new Featurevisor instance with datafile
692+
* @param datafile the datafile content
693+
* @return new Instance
694+
*/
695+
public static Instance createInstance(DatafileContent datafile) {
696+
InstanceOptions options = new InstanceOptions();
697+
options.setDatafile(datafile);
698+
return new Instance(options);
699+
}
700+
701+
/**
702+
* Create a new Featurevisor instance with datafile string
703+
* @param datafileString JSON string of the datafile
704+
* @return new Instance
705+
*/
706+
public static Instance createInstance(String datafileString) {
707+
InstanceOptions options = new InstanceOptions();
708+
options.setDatafileString(datafileString);
709+
return new Instance(options);
710+
}
711+
712+
/**
713+
* Create a new Featurevisor instance with context
714+
* @param context the context map
715+
* @return new Instance
716+
*/
717+
public static Instance createInstance(Map<String, Object> context) {
718+
InstanceOptions options = new InstanceOptions();
719+
options.setContext(context);
720+
return new Instance(options);
721+
}
722+
723+
/**
724+
* Create a new Featurevisor instance with full options
725+
* @param options the instance options
726+
* @return new Instance
727+
*/
728+
public static Instance createInstance(InstanceOptions options) {
729+
return new Instance(options);
679730
}
680731
}

0 commit comments

Comments
 (0)