Skip to content

Commit

Permalink
use @slf4j for logging in all cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
wangmingliang-ms committed Apr 7, 2023
1 parent 42adc79 commit 40e01c8
Show file tree
Hide file tree
Showing 25 changed files with 182 additions and 252 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
import com.microsoft.azure.toolkit.lib.auth.AzureAccount;
import com.microsoft.azure.toolkit.lib.common.exception.AzureExecutionException;
import com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException;
import com.microsoft.azure.toolkit.lib.common.logging.Log;
import com.microsoft.azure.toolkit.lib.common.model.Subscription;
import com.microsoft.azure.toolkit.lib.common.utils.TextUtils;
import com.microsoft.azure.toolkit.lib.legacy.appservice.DeploymentSlotSetting;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.apache.maven.plugins.annotations.Parameter;

import java.io.IOException;
Expand All @@ -34,6 +34,7 @@
/**
* Base abstract class for all Azure App Service Mojos.
*/
@Slf4j
public abstract class AbstractAppServiceMojo extends AbstractAzureMojo {
protected static final String MAVEN_PLUGIN_POSTFIX = "-maven-plugin";

Expand Down Expand Up @@ -169,7 +170,7 @@ protected void printCurrentSubscription(AzureAppService appServiceClient) {
final List<Subscription> subscriptions = Azure.az(IAzureAccount.class).account().getSelectedSubscriptions();
final Subscription subscription = subscriptions.get(0);
if (subscription != null) {
Log.info(String.format(AbstractAzureMojo.SUBSCRIPTION_TEMPLATE, TextUtils.cyan(subscription.getName()), TextUtils.cyan(subscription.getId())));
log.info(String.format(AbstractAzureMojo.SUBSCRIPTION_TEMPLATE, TextUtils.cyan(subscription.getName()), TextUtils.cyan(subscription.getId())));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
package com.microsoft.azure.maven.function;

import com.microsoft.azure.toolkit.lib.common.exception.AzureExecutionException;
import com.microsoft.azure.toolkit.lib.common.logging.Log;
import com.microsoft.azure.toolkit.lib.common.operation.AzureOperation;
import com.microsoft.azure.toolkit.lib.legacy.function.configurations.FunctionExtensionVersion;
import com.microsoft.azure.toolkit.lib.legacy.function.template.BindingConfiguration;
Expand All @@ -15,6 +14,7 @@
import com.microsoft.azure.toolkit.lib.legacy.function.template.FunctionTemplate;
import com.microsoft.azure.toolkit.lib.legacy.function.template.TemplateResources;
import com.microsoft.azure.toolkit.lib.legacy.function.utils.FunctionUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.maven.plugin.MojoFailureException;
Expand Down Expand Up @@ -47,6 +47,7 @@
/**
* Create new Azure Functions (as Java class) and add to current project.
*/
@Slf4j
@Mojo(name = "add")
public class AddMojo extends AbstractFunctionMojo {
private static final String LOAD_TEMPLATES = "Step 1 of 4: Load all function templates";
Expand Down Expand Up @@ -166,22 +167,22 @@ protected void doExecute() throws AzureExecutionException {

//region Load templates
protected List<FunctionTemplate> loadAllFunctionTemplates(FunctionExtensionVersion bundleVersion) throws AzureExecutionException {
Log.info("");
Log.info(LOAD_TEMPLATES);
log.info("");
log.info(LOAD_TEMPLATES);
final List<FunctionTemplate> templates = FunctionUtils.loadAllFunctionTemplates()
.stream()
.filter(template -> ObjectUtils.anyNull(bundleVersion, template.getSupportedExtensionVersions()) || template.getSupportedExtensionVersions().contains(bundleVersion))
.collect(Collectors.toList());
Log.info(LOAD_TEMPLATES_DONE);
log.info(LOAD_TEMPLATES_DONE);
return templates;
}

//endregion

//region Get function template
protected FunctionTemplate getFunctionTemplate(final List<FunctionTemplate> templates) throws IOException, AzureExecutionException, MojoFailureException {
Log.info("");
Log.info(FIND_TEMPLATE);
log.info("");
log.info(FIND_TEMPLATE);

if (settings != null && !settings.isInteractiveMode()) {
assureInputInBatchMode(getFunctionTemplate(),
Expand All @@ -208,13 +209,13 @@ protected List<String> getTemplateNames(final List<FunctionTemplate> templates)

protected FunctionTemplate findTemplateByName(final List<FunctionTemplate> templates, final String templateName)
throws AzureExecutionException {
Log.info("Selected function template: " + templateName);
log.info("Selected function template: " + templateName);
final Optional<FunctionTemplate> template = templates.stream()
.filter(t -> t.getMetadata().getName().equalsIgnoreCase(templateName))
.findFirst();

if (template.isPresent()) {
Log.info(FIND_TEMPLATE_DONE + templateName);
log.info(FIND_TEMPLATE_DONE + templateName);
return template.get();
}

Expand All @@ -228,8 +229,8 @@ protected FunctionTemplate findTemplateByName(final List<FunctionTemplate> templ
protected Map<String, String> prepareRequiredParameters(final FunctionTemplate template,
final BindingTemplate bindingTemplate)
throws MojoFailureException {
Log.info("");
Log.info(PREPARE_PARAMS);
log.info("");
log.info(PREPARE_PARAMS);

prepareFunctionName();

Expand All @@ -248,7 +249,7 @@ protected Map<String, String> prepareRequiredParameters(final FunctionTemplate t
}

protected void prepareFunctionName() throws MojoFailureException {
Log.info("Common parameter [Function Name]: name for both the new function and Java class");
log.info("Common parameter [Function Name]: name for both the new function and Java class");

if (settings != null && !settings.isInteractiveMode()) {
assureInputInBatchMode(getFunctionName(), str -> StringUtils.isNotEmpty(str) && str.matches(FUNCTION_NAME_REGEXP), this::setFunctionName, true);
Expand All @@ -259,7 +260,7 @@ protected void prepareFunctionName() throws MojoFailureException {
}

protected void preparePackageName() throws MojoFailureException {
Log.info("Common parameter [Package Name]: package name of the new Java class");
log.info("Common parameter [Package Name]: package name of the new Java class");

if (settings != null && !settings.isInteractiveMode()) {
assureInputInBatchMode(getFunctionPackageName(), str -> StringUtils.isNotEmpty(str) && isName(str), this::setFunctionPackageName, true);
Expand All @@ -282,7 +283,7 @@ protected Map<String, String> prepareTemplateParameters(final FunctionTemplate t
final String helpMessage = (settingTemplate != null && settingTemplate.getHelp() != null) ?
settingTemplate.getHelp() : "";

Log.info(format("Trigger specific parameter [%s]:%s", property,
log.info(format("Trigger specific parameter [%s]:%s", property,
TemplateResources.getResource(helpMessage)));
if (settings != null && !settings.isInteractiveMode()) {
if (options != null && options.size() > 0) {
Expand All @@ -308,7 +309,7 @@ protected String getStringInputFromUser(String attributeName, String initValue,
final Function<String, Boolean> validator = getStringInputValidator(template);

if (validator.apply(initValue)) {
Log.info(FOUND_VALID_VALUE);
log.info(FOUND_VALID_VALUE);
return initValue;
}

Expand All @@ -322,7 +323,7 @@ protected String getStringInputFromUser(String attributeName, String initValue,
} else if (StringUtils.isNotEmpty(defaultValue) && StringUtils.isEmpty(input)) {
return defaultValue;
}
Log.warn(getStringInputErrorMessage(template));
log.warn(getStringInputErrorMessage(template));
}
}

Expand All @@ -347,10 +348,10 @@ protected Function<String, Boolean> getStringInputValidator(FunctionSettingTempl
}

protected void displayParameters(final Map<String, String> params) {
Log.info("");
Log.info("Summary of parameters for function template:");
log.info("");
log.info("Summary of parameters for function template:");

params.entrySet().stream().forEach(e -> Log.info(format("%s: %s", e.getKey(), e.getValue())));
params.entrySet().stream().forEach(e -> log.info(format("%s: %s", e.getKey(), e.getValue())));
}

//endregion
Expand All @@ -370,8 +371,8 @@ protected String substituteParametersInTemplate(final FunctionTemplate template,
//region Save function to file

protected void saveNewFunctionToFile(final String newFunctionClass) throws IOException, AzureExecutionException {
Log.info("");
Log.info(SAVE_FILE);
log.info("");
log.info(SAVE_FILE);

final File packageDir = getPackageDir();

Expand All @@ -381,7 +382,7 @@ protected void saveNewFunctionToFile(final String newFunctionClass) throws IOExc

saveToTargetFile(targetFile, newFunctionClass);

Log.info(SAVE_FILE_DONE + targetFile.getAbsolutePath());
log.info(SAVE_FILE_DONE + targetFile.getAbsolutePath());
}

protected File getPackageDir() {
Expand Down Expand Up @@ -419,7 +420,7 @@ protected void assureInputFromUser(final String prompt, final String initValue,
final Consumer<String> setter) {
final String option = findElementInOptions(options, initValue);
if (option != null) {
Log.info(FOUND_VALID_VALUE);
log.info(FOUND_VALID_VALUE);
setter.accept(option);
return;
}
Expand Down Expand Up @@ -447,7 +448,7 @@ protected void assureInputFromUser(final String prompt, final String initValue,
final Function<String, Boolean> validator, final String errorMessage,
final Consumer<String> setter) {
if (validator.apply(initValue)) {
Log.info(FOUND_VALID_VALUE);
log.info(FOUND_VALID_VALUE);
setter.accept(initValue);
return;
}
Expand All @@ -466,15 +467,15 @@ protected void assureInputFromUser(final String prompt, final String initValue,
} catch (Exception ignored) {
}
// Reaching here means invalid input
Log.warn(errorMessage);
log.warn(errorMessage);
}
}

protected void assureInputInBatchMode(final String input, final Function<String, Boolean> validator,
final Consumer<String> setter, final boolean required)
throws MojoFailureException {
if (validator.apply(input)) {
Log.info(FOUND_VALID_VALUE);
log.info(FOUND_VALID_VALUE);
setter.accept(input);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
package com.microsoft.azure.maven.function;

import com.microsoft.azure.toolkit.lib.common.exception.AzureExecutionException;
import com.microsoft.azure.toolkit.lib.common.logging.Log;
import com.microsoft.azure.toolkit.lib.common.operation.AzureOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.IOUtils;
import org.apache.maven.plugins.annotations.Mojo;

Expand All @@ -18,6 +18,7 @@
* The list mojo is used to provide Java Azure Functions templates information,
* which is used by other tools such as VS Code Azure Functions extension.
*/
@Slf4j
@Mojo(name = "list")
public class ListMojo extends AbstractFunctionMojo {

Expand All @@ -38,17 +39,17 @@ public class ListMojo extends AbstractFunctionMojo {
@AzureOperation("user/functionapp.list")
protected void doExecute() throws AzureExecutionException {
try {
Log.info(TEMPLATES_START);
log.info(TEMPLATES_START);
printToSystemOut(TEMPLATES_FILE);
Log.info(TEMPLATES_END);
log.info(TEMPLATES_END);

Log.info(BINDINGS_START);
log.info(BINDINGS_START);
printToSystemOut(BINDINGS_FILE);
Log.info(BINDINGS_END);
log.info(BINDINGS_END);

Log.info(RESOURCES_START);
log.info(RESOURCES_START);
printToSystemOut(RESOURCES_FILE);
Log.info(RESOURCES_END);
log.info(RESOURCES_END);
} catch (IOException e) {
throw new AzureExecutionException("IO error when printing templates:" + e.getMessage(), e);
}
Expand Down
Loading

0 comments on commit 40e01c8

Please sign in to comment.