Skip to content

Commit

Permalink
client, generate SDK should use structured log (#2651)
Browse files Browse the repository at this point in the history
  • Loading branch information
weidongxu-microsoft committed Mar 28, 2024
1 parent bdcd1fd commit 0d202bc
Show file tree
Hide file tree
Showing 189 changed files with 1,616 additions and 1,602 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public FormRecognizerClientBuilder() {
@Override
public FormRecognizerClientBuilder pipeline(HttpPipeline pipeline) {
if (this.pipeline != null && pipeline == null) {
LOGGER.info("HttpPipeline is being set to 'null' when it was previously configured.");
LOGGER.atInfo().log("HttpPipeline is being set to 'null' when it was previously configured.");
}
this.pipeline = pipeline;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,15 +192,15 @@ private static String addLogging(LogLevel level, String message) {
if (JavaSettings.getInstance().isBranded()) {
switch (level) {
case VERBOSE:
return String.format("LOGGER.verbose(\"%s\");", message);
return String.format("LOGGER.atVerbose().log(\"%s\");", message);
case INFORMATIONAL:
return String.format("LOGGER.info(\"%s\");", message);
return String.format("LOGGER.atInfo().log(\"%s\");", message);
case WARNING:
return String.format("LOGGER.warning(\"%s\");", message);
return String.format("LOGGER.atWarning().log(\"%s\");", message);
case ERROR:
return String.format("LOGGER.error(\"%s\");", message);
return String.format("LOGGER.atError().log(\"%s\");", message);
default:
return String.format("LOGGER.info(\"%s\");", message);
return String.format("LOGGER.atInfo().log(\"%s\");", message);
}
} else {
switch (level) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ protected static void addValidations(JavaBlock function, List<String> expression
JavaIfBlock nullCheck = function.ifBlock(expressionToCheck + " == null", ifBlock -> {
if (JavaSettings.getInstance().isSyncStackEnabled()) {
if (settings.isUseClientLogger()) {
ifBlock.line("throw LOGGER.logExceptionAsError(%s);", exceptionExpression);
ifBlock.line("throw LOGGER.atError().log(%s);", exceptionExpression);
} else {
ifBlock.line("throw %s;", exceptionExpression);
}
Expand Down Expand Up @@ -1010,7 +1010,7 @@ protected void generateSyncMethod(ClientMethod clientMethod, JavaType typeBlock,
ifAction.methodReturn("value");
}).elseBlock(elseAction -> {
if (settings.isUseClientLogger()) {
elseAction.line("throw LOGGER.logExceptionAsError(new NullPointerException());");
elseAction.line("throw LOGGER.atError().log(new NullPointerException());");
} else {
elseAction.line("throw new NullPointerException();");
}
Expand Down Expand Up @@ -1088,7 +1088,7 @@ protected void generatePlainSyncMethod(ClientMethod clientMethod, JavaType typeB
ifAction.methodReturn("value");
}).elseBlock(elseAction -> {
if (settings.isUseClientLogger()) {
elseAction.line("throw LOGGER.logExceptionAsError(new NullPointerException());");
elseAction.line("throw LOGGER.atError().log(new NullPointerException());");
} else {
elseAction.line("throw new NullPointerException();");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ protected void writeInvocationAndConversion(
@Override
protected void writeThrowException(ClientMethodType methodType, String exceptionExpression, JavaBlock methodBlock) {
if (JavaSettings.getInstance().isUseClientLogger()) {
methodBlock.line(String.format("throw LOGGER.logExceptionAsError(%s);", exceptionExpression));
methodBlock.line(String.format("throw LOGGER.atError().log(%s);", exceptionExpression));
} else {
methodBlock.line(String.format("throw %s;", exceptionExpression));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1040,7 +1040,7 @@ private void addPropertyValidations(JavaClass classBlock, ClientModel model, Jav
final String errorMessage = String.format("\"Missing required property %s in model %s\"", property.getName(), model.getName());
if (settings.isUseClientLogger()) {
ifBlock.line(String.format(
"throw LOGGER.logExceptionAsError(new IllegalArgumentException(%s));",
"throw LOGGER.atError().log(new IllegalArgumentException(%s));",
errorMessage));
} else {
ifBlock.line(String.format(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ private static void generateHeaderDeserializationFunction(ClientModelProperty pr
// At this time all try-catching is for IOExceptions.
javaBlock.decreaseIndent();
javaBlock.line("} catch (IOException ex) {");
javaBlock.indent(() -> javaBlock.line("throw LOGGER.logExceptionAsError(new UncheckedIOException(ex));"));
javaBlock.indent(() -> javaBlock.line("throw LOGGER.atError().log(new UncheckedIOException(ex));"));
javaBlock.line("}");
}
}
Expand Down
13 changes: 7 additions & 6 deletions javagen/src/main/java/com/azure/autorest/util/TemplateUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,11 @@ public static String getTypeReferenceCreation(IType type) {
return (type instanceof ArrayType || type instanceof ClassType || type instanceof EnumType || type instanceof PrimitiveType)
? type.asNullable() + ".class"
: CodeNamer.getEnumMemberName("TypeReference" + ((GenericType) type).toJavaPropertyString());
} else {
return (type instanceof ArrayType || type instanceof ClassType || type instanceof EnumType || type instanceof PrimitiveType)
? String.format("TypeReference.createInstance(%s.class)", type.asNullable())
: CodeNamer.getEnumMemberName("TypeReference" + ((GenericType) type).toJavaPropertyString());
}
return (type instanceof ArrayType || type instanceof ClassType || type instanceof EnumType || type instanceof PrimitiveType)
? String.format("TypeReference.createInstance(%s.class)", type.asNullable())
: CodeNamer.getEnumMemberName("TypeReference" + ((GenericType) type).toJavaPropertyString());
}

/**
Expand All @@ -224,10 +225,10 @@ public static void writeTypeReferenceStaticVariable(JavaClass classBlock, Generi
+ "@Override public Type[] getActualTypeArguments() { return new Type[] { " + sb + " }; }"
+ "@Override public Type getOwnerType() { return null; } }",
CodeNamer.getEnumMemberName("TypeReference" + type.toJavaPropertyString())));
return;
} else {
classBlock.privateStaticFinalVariable(String.format("TypeReference<%1$s> %2$s = new TypeReference<%1$s>() {}",
type, CodeNamer.getEnumMemberName("TypeReference" + type.toJavaPropertyString())));
}
classBlock.privateStaticFinalVariable(String.format("TypeReference<%1$s> %2$s = new TypeReference<%1$s>() {}",
type, CodeNamer.getEnumMemberName("TypeReference" + type.toJavaPropertyString())));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public AutoRestSwaggerBatServiceClientBuilder() {
@Override
public AutoRestSwaggerBatServiceClientBuilder pipeline(HttpPipeline pipeline) {
if (this.pipeline != null && pipeline == null) {
LOGGER.info("HttpPipeline is being set to 'null' when it was previously configured.");
LOGGER.atInfo().log("HttpPipeline is being set to 'null' when it was previously configured.");
}
this.pipeline = pipeline;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public DpgClientBuilder() {
@Override
public DpgClientBuilder pipeline(HttpPipeline pipeline) {
if (this.pipeline != null && pipeline == null) {
LOGGER.info("HttpPipeline is being set to 'null' when it was previously configured.");
LOGGER.atInfo().log("HttpPipeline is being set to 'null' when it was previously configured.");
}
this.pipeline = pipeline;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public DpgClientBuilder() {
@Override
public DpgClientBuilder pipeline(HttpPipeline pipeline) {
if (this.pipeline != null && pipeline == null) {
LOGGER.info("HttpPipeline is being set to 'null' when it was previously configured.");
LOGGER.atInfo().log("HttpPipeline is being set to 'null' when it was previously configured.");
}
this.pipeline = pipeline;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public ArrayClientBuilder() {
@Override
public ArrayClientBuilder pipeline(HttpPipeline pipeline) {
if (this.pipeline != null && pipeline == null) {
LOGGER.info("HttpPipeline is being set to 'null' when it was previously configured.");
LOGGER.atInfo().log("HttpPipeline is being set to 'null' when it was previously configured.");
}
this.pipeline = pipeline;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public BasicClientBuilder() {
@Override
public BasicClientBuilder pipeline(HttpPipeline pipeline) {
if (this.pipeline != null && pipeline == null) {
LOGGER.info("HttpPipeline is being set to 'null' when it was previously configured.");
LOGGER.atInfo().log("HttpPipeline is being set to 'null' when it was previously configured.");
}
this.pipeline = pipeline;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public DictionaryClientBuilder() {
@Override
public DictionaryClientBuilder pipeline(HttpPipeline pipeline) {
if (this.pipeline != null && pipeline == null) {
LOGGER.info("HttpPipeline is being set to 'null' when it was previously configured.");
LOGGER.atInfo().log("HttpPipeline is being set to 'null' when it was previously configured.");
}
this.pipeline = pipeline;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public FlattencomplexClientBuilder() {
@Override
public FlattencomplexClientBuilder pipeline(HttpPipeline pipeline) {
if (this.pipeline != null && pipeline == null) {
LOGGER.info("HttpPipeline is being set to 'null' when it was previously configured.");
LOGGER.atInfo().log("HttpPipeline is being set to 'null' when it was previously configured.");
}
this.pipeline = pipeline;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public InheritanceClientBuilder() {
@Override
public InheritanceClientBuilder pipeline(HttpPipeline pipeline) {
if (this.pipeline != null && pipeline == null) {
LOGGER.info("HttpPipeline is being set to 'null' when it was previously configured.");
LOGGER.atInfo().log("HttpPipeline is being set to 'null' when it was previously configured.");
}
this.pipeline = pipeline;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public PolymorphicrecursiveClientBuilder() {
@Override
public PolymorphicrecursiveClientBuilder pipeline(HttpPipeline pipeline) {
if (this.pipeline != null && pipeline == null) {
LOGGER.info("HttpPipeline is being set to 'null' when it was previously configured.");
LOGGER.atInfo().log("HttpPipeline is being set to 'null' when it was previously configured.");
}
this.pipeline = pipeline;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public PolymorphismClientBuilder() {
@Override
public PolymorphismClientBuilder pipeline(HttpPipeline pipeline) {
if (this.pipeline != null && pipeline == null) {
LOGGER.info("HttpPipeline is being set to 'null' when it was previously configured.");
LOGGER.atInfo().log("HttpPipeline is being set to 'null' when it was previously configured.");
}
this.pipeline = pipeline;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public PrimitiveClientBuilder() {
@Override
public PrimitiveClientBuilder pipeline(HttpPipeline pipeline) {
if (this.pipeline != null && pipeline == null) {
LOGGER.info("HttpPipeline is being set to 'null' when it was previously configured.");
LOGGER.atInfo().log("HttpPipeline is being set to 'null' when it was previously configured.");
}
this.pipeline = pipeline;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public ReadonlypropertyClientBuilder() {
@Override
public ReadonlypropertyClientBuilder pipeline(HttpPipeline pipeline) {
if (this.pipeline != null && pipeline == null) {
LOGGER.info("HttpPipeline is being set to 'null' when it was previously configured.");
LOGGER.atInfo().log("HttpPipeline is being set to 'null' when it was previously configured.");
}
this.pipeline = pipeline;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public AutoRestSwaggerBatFileServiceClientBuilder() {
@Override
public AutoRestSwaggerBatFileServiceClientBuilder pipeline(HttpPipeline pipeline) {
if (this.pipeline != null && pipeline == null) {
LOGGER.info("HttpPipeline is being set to 'null' when it was previously configured.");
LOGGER.atInfo().log("HttpPipeline is being set to 'null' when it was previously configured.");
}
this.pipeline = pipeline;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public EnumClientBuilder() {
@Override
public EnumClientBuilder pipeline(HttpPipeline pipeline) {
if (this.pipeline != null && pipeline == null) {
LOGGER.info("HttpPipeline is being set to 'null' when it was previously configured.");
LOGGER.atInfo().log("HttpPipeline is being set to 'null' when it was previously configured.");
}
this.pipeline = pipeline;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public StringOperationClientBuilder() {
@Override
public StringOperationClientBuilder pipeline(HttpPipeline pipeline) {
if (this.pipeline != null && pipeline == null) {
LOGGER.info("HttpPipeline is being set to 'null' when it was previously configured.");
LOGGER.atInfo().log("HttpPipeline is being set to 'null' when it was previously configured.");
}
this.pipeline = pipeline;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public ConstantAndClientParameterServiceClientBuilder() {
@Override
public ConstantAndClientParameterServiceClientBuilder pipeline(HttpPipeline pipeline) {
if (this.pipeline != null && pipeline == null) {
LOGGER.info("HttpPipeline is being set to 'null' when it was previously configured.");
LOGGER.atInfo().log("HttpPipeline is being set to 'null' when it was previously configured.");
}
this.pipeline = pipeline;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public AutoRestSwaggerConstantServiceClientBuilder() {
@Override
public AutoRestSwaggerConstantServiceClientBuilder pipeline(HttpPipeline pipeline) {
if (this.pipeline != null && pipeline == null) {
LOGGER.info("HttpPipeline is being set to 'null' when it was previously configured.");
LOGGER.atInfo().log("HttpPipeline is being set to 'null' when it was previously configured.");
}
this.pipeline = pipeline;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public DpgClientBuilder() {
@Override
public DpgClientBuilder pipeline(HttpPipeline pipeline) {
if (this.pipeline != null && pipeline == null) {
LOGGER.info("HttpPipeline is being set to 'null' when it was previously configured.");
LOGGER.atInfo().log("HttpPipeline is being set to 'null' when it was previously configured.");
}
this.pipeline = pipeline;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public LroEndpointClientBuilder() {
@Override
public LroEndpointClientBuilder pipeline(HttpPipeline pipeline) {
if (this.pipeline != null && pipeline == null) {
LOGGER.info("HttpPipeline is being set to 'null' when it was previously configured.");
LOGGER.atInfo().log("HttpPipeline is being set to 'null' when it was previously configured.");
}
this.pipeline = pipeline;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public EnumServiceClientBuilder() {
@Override
public EnumServiceClientBuilder pipeline(HttpPipeline pipeline) {
if (this.pipeline != null && pipeline == null) {
LOGGER.info("HttpPipeline is being set to 'null' when it was previously configured.");
LOGGER.atInfo().log("HttpPipeline is being set to 'null' when it was previously configured.");
}
this.pipeline = pipeline;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public AutoRestSwaggerBatHeaderServiceClientBuilder() {
@Override
public AutoRestSwaggerBatHeaderServiceClientBuilder pipeline(HttpPipeline pipeline) {
if (this.pipeline != null && pipeline == null) {
LOGGER.info("HttpPipeline is being set to 'null' when it was previously configured.");
LOGGER.atInfo().log("HttpPipeline is being set to 'null' when it was previously configured.");
}
this.pipeline = pipeline;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public AutoRestHeadExceptionTestServiceClientBuilder() {
@Override
public AutoRestHeadExceptionTestServiceClientBuilder pipeline(HttpPipeline pipeline) {
if (this.pipeline != null && pipeline == null) {
LOGGER.info("HttpPipeline is being set to 'null' when it was previously configured.");
LOGGER.atInfo().log("HttpPipeline is being set to 'null' when it was previously configured.");
}
this.pipeline = pipeline;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public HttpClientFailureClientBuilder() {
@Override
public HttpClientFailureClientBuilder pipeline(HttpPipeline pipeline) {
if (this.pipeline != null && pipeline == null) {
LOGGER.info("HttpPipeline is being set to 'null' when it was previously configured.");
LOGGER.atInfo().log("HttpPipeline is being set to 'null' when it was previously configured.");
}
this.pipeline = pipeline;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public HttpFailureClientBuilder() {
@Override
public HttpFailureClientBuilder pipeline(HttpPipeline pipeline) {
if (this.pipeline != null && pipeline == null) {
LOGGER.info("HttpPipeline is being set to 'null' when it was previously configured.");
LOGGER.atInfo().log("HttpPipeline is being set to 'null' when it was previously configured.");
}
this.pipeline = pipeline;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public HttpRedirectsClientBuilder() {
@Override
public HttpRedirectsClientBuilder pipeline(HttpPipeline pipeline) {
if (this.pipeline != null && pipeline == null) {
LOGGER.info("HttpPipeline is being set to 'null' when it was previously configured.");
LOGGER.atInfo().log("HttpPipeline is being set to 'null' when it was previously configured.");
}
this.pipeline = pipeline;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public HttpRetryClientBuilder() {
@Override
public HttpRetryClientBuilder pipeline(HttpPipeline pipeline) {
if (this.pipeline != null && pipeline == null) {
LOGGER.info("HttpPipeline is being set to 'null' when it was previously configured.");
LOGGER.atInfo().log("HttpPipeline is being set to 'null' when it was previously configured.");
}
this.pipeline = pipeline;
return this;
Expand Down
Loading

0 comments on commit 0d202bc

Please sign in to comment.