Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cwms-data-api/src/main/java/cwms/cda/ApiServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@
})
public class ApiServlet extends HttpServlet {

public static final FluentLogger logger = FluentLogger.forEnclosingClass();
private static final FluentLogger logger = FluentLogger.forEnclosingClass();

// based on https://bitbucket.hecdev.net/projects/CWMS/repos/cwms_aaa/browse/IntegrationTests/src/test/resources/sql/load_testusers.sql
public static final String CWMS_USERS_ROLE = "CWMS Users";
Expand Down
7 changes: 3 additions & 4 deletions cwms-data-api/src/main/java/cwms/cda/api/BasinController.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,14 @@
import java.sql.SQLException;
import java.util.Collections;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.google.common.flogger.FluentLogger;
import javax.servlet.http.HttpServletResponse;
import org.jetbrains.annotations.NotNull;
import org.jooq.DSLContext;


public class BasinController implements CrudHandler {
private static final Logger LOGGER = Logger.getLogger(BasinController.class.getName());
private static final FluentLogger LOGGER = FluentLogger.forEnclosingClass();
public static final String TAG = "Basins";

private final MetricRegistry metrics;
Expand Down Expand Up @@ -143,7 +142,7 @@ public void getAll(@NotNull Context ctx) {
ctx.status(HttpServletResponse.SC_OK);
} catch (SQLException ex) {
CdaError error = new CdaError("Error retrieving all basins");
LOGGER.log(Level.SEVERE, "Error retrieving all basins", ex);
LOGGER.atSevere().withCause(ex).log("Error retrieving all basins");
ctx.status(HttpServletResponse.SC_INTERNAL_SERVER_ERROR).json(error);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,15 @@
import java.net.URISyntaxException;
import java.net.URLEncoder;
import java.time.Instant;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.google.common.flogger.FluentLogger;
import javax.servlet.http.HttpServletResponse;
import org.apache.http.client.utils.URIBuilder;
import org.jetbrains.annotations.NotNull;
import org.jooq.DSLContext;


public class BinaryTimeSeriesController implements CrudHandler {
private static final Logger logger = Logger.getLogger(BinaryTimeSeriesController.class.getName());
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
static final String TAG = "Binary-TimeSeries";

public static final String REPLACE_ALL = "replace-all";
Expand Down Expand Up @@ -172,7 +171,7 @@ public void getAll(@NotNull Context ctx) {
} catch (URISyntaxException | UnsupportedEncodingException ex) {
CdaError re =
new CdaError("Failed to process request: " + ex.getLocalizedMessage());
logger.log(Level.SEVERE, re.toString(), ex);
logger.atSevere().withCause(ex).log("%s", re);
ctx.status(HttpServletResponse.SC_INTERNAL_SERVER_ERROR).json(re);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.logging.Logger;
import com.google.common.flogger.FluentLogger;
import org.jetbrains.annotations.NotNull;
import org.jooq.DSLContext;
import org.owasp.html.PolicyFactory;

public class CatalogController implements CrudHandler {

private static final Logger logger = Logger.getLogger(CatalogController.class.getName());
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
private static final String TAG = "Catalog";
public static final boolean INCLUDE_EXTENTS_DEFAULT = true;
public static final boolean EXCLUDE_EMPTY_DEFAULT = true;
Expand Down Expand Up @@ -285,7 +285,7 @@ public void getOne(@NotNull Context ctx, @NotNull String dataSet) {
final CdaError re = new CdaError("Cannot create catalog of requested "
+ "information");

logger.info(() -> re + " with url:" + ctx.fullUrl());
logger.atInfo().log("%s with url:%s", re, ctx.fullUrl());
ctx.json(re).status(HttpCode.NOT_FOUND);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import io.javalin.plugin.openapi.annotations.OpenApiRequestBody;
import org.jetbrains.annotations.NotNull;
import org.jooq.DSLContext;
import java.util.logging.Logger;

import static com.codahale.metrics.MetricRegistry.name;
import static cwms.cda.api.Controllers.FORECAST_DATE;
Expand All @@ -30,7 +29,6 @@
import static cwms.cda.api.Controllers.TIMESERIES_ID;

public class ForecastTimeseriesController implements CrudHandler {
private static final Logger logger = Logger.getLogger(ForecastSpecController.class.getName());

public static final String TAG = "Forecast";
private final MetricRegistry metrics;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,13 @@
import io.javalin.plugin.openapi.annotations.OpenApiResponse;
import java.util.List;
import java.util.Optional;
import java.util.logging.Logger;
import com.google.common.flogger.FluentLogger;
import javax.servlet.http.HttpServletResponse;
import org.jetbrains.annotations.NotNull;
import org.jooq.DSLContext;

public class LocationCategoryController implements CrudHandler {
public static final Logger logger =
Logger.getLogger(LocationCategoryController.class.getName());
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
private static final String TAG = "Location Categories";

private final MetricRegistry metrics;
Expand Down Expand Up @@ -111,11 +110,7 @@ public void getAll(Context ctx) {
CdaError re = new CdaError("Cannot find requested location category for "
+ "office provided: " + office);

logger.info(() -> {
StringBuilder builder = new StringBuilder(re.toString())
.append("with url:").append(ctx.fullUrl());
return builder.toString();
});
logger.atInfo().log("%s with url:%s", re, ctx.fullUrl());
ctx.json(re).status(HttpServletResponse.SC_NOT_FOUND);
}

Expand Down Expand Up @@ -167,11 +162,7 @@ public void getOne(Context ctx, @NotNull String categoryId) {
CdaError re = new CdaError("Cannot find requested location category id: " + categoryId
+ " with office: " + office);

logger.info(() -> {
StringBuilder builder = new StringBuilder(re.toString())
.append("with url:").append(ctx.fullUrl());
return builder.toString();
});
logger.atInfo().log("%s with url:%s", re, ctx.fullUrl());
ctx.json(re).status(HttpServletResponse.SC_NOT_FOUND);
}

Expand Down
13 changes: 6 additions & 7 deletions cwms-data-api/src/main/java/cwms/cda/api/LocationController.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.google.common.flogger.FluentLogger;
import javax.servlet.http.HttpServletResponse;
import org.geojson.FeatureCollection;
import org.jetbrains.annotations.NotNull;
Expand All @@ -73,7 +72,7 @@


public class LocationController implements CrudHandler {
public static final Logger logger = Logger.getLogger(LocationController.class.getName());
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
private final MetricRegistry metrics;

private final Histogram requestResultSize;
Expand Down Expand Up @@ -199,7 +198,7 @@ public void getAll(@NotNull Context ctx) {

} catch (Exception ex) {
CdaError re = new CdaError("failed to process request");
logger.log(Level.SEVERE, re.toString(), ex);
logger.atSevere().withCause(ex).log("%s", re.toString());
ctx.status(HttpServletResponse.SC_INTERNAL_SERVER_ERROR).json(re);
}
}
Expand Down Expand Up @@ -254,7 +253,7 @@ public void getOne(@NotNull Context ctx, @NotNull String name) {
String errorMsg = "Error retrieving " + name;
CdaError re = new CdaError(errorMsg);
ctx.status(HttpServletResponse.SC_INTERNAL_SERVER_ERROR).json(re);
logger.log(Level.SEVERE, errorMsg, ex);
logger.atSevere().withCause(ex).log("%s", errorMsg);
}
}

Expand Down Expand Up @@ -295,7 +294,7 @@ public void create(@NotNull Context ctx) {
ctx.status(HttpServletResponse.SC_CREATED).json(re);
} catch (IOException ex) {
CdaError re = new CdaError("failed to process request");
logger.log(Level.SEVERE, re.toString(), ex);
logger.atSevere().withCause(ex).log("%s", re.toString());
ctx.status(HttpServletResponse.SC_INTERNAL_SERVER_ERROR).json(re);
}
}
Expand Down Expand Up @@ -347,7 +346,7 @@ public void update(@NotNull Context ctx, @NotNull String locationId) {
} catch (IOException ex) {
CdaError re =
new CdaError("Failed to process request: " + ex.getLocalizedMessage());
logger.log(Level.SEVERE, re.toString(), ex);
logger.atSevere().withCause(ex).log("%s", re.toString());
ctx.status(HttpServletResponse.SC_INTERNAL_SERVER_ERROR).json(re);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,14 @@
import io.javalin.plugin.openapi.annotations.OpenApiResponse;
import java.util.List;
import java.util.Optional;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.google.common.flogger.FluentLogger;
import javax.servlet.http.HttpServletResponse;
import org.geojson.FeatureCollection;
import org.jetbrains.annotations.NotNull;
import org.jooq.DSLContext;

public class LocationGroupController implements CrudHandler {
public static final Logger logger = Logger.getLogger(LocationGroupController.class.getName());
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
private static final String LOCATION_OFFICE_ID = "location-office-id";

public static final String TAG = "Location Groups";
Expand Down Expand Up @@ -136,7 +135,7 @@ Boolean.class, false, metrics, name(LocationGroupController.class.getName(),
ctx.status(HttpServletResponse.SC_OK);
} else {
CdaError re = new CdaError("No location groups for office provided");
logger.info(() -> re + System.lineSeparator() + "for request " + ctx.fullUrl());
logger.atInfo().log("%s%nfor request %s", re, ctx.fullUrl());
ctx.status(HttpServletResponse.SC_NOT_FOUND).json(re);
}

Expand Down Expand Up @@ -200,7 +199,7 @@ public void getOne(@NotNull Context ctx, @NotNull String groupId) {
result = Formats.format(contentType, grp.get());
} else {
CdaError re = new CdaError("Unable to find location group based on parameters given");
logger.info(() -> re + System.lineSeparator() + "for request " + ctx.fullUrl());
logger.atInfo().log("%s%nfor request %s", re, ctx.fullUrl());
ctx.status(HttpServletResponse.SC_NOT_FOUND).json(re);
return;
}
Expand All @@ -214,7 +213,7 @@ public void getOne(@NotNull Context ctx, @NotNull String groupId) {
ctx.status(HttpServletResponse.SC_OK);
} catch (JsonProcessingException e) {
CdaError re = new CdaError("Failed to process request");
logger.log(Level.SEVERE, re.toString(), e);
logger.atSevere().withCause(e).log("%s", re);
ctx.status(HttpServletResponse.SC_INTERNAL_SERVER_ERROR).json(re);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,12 @@
import io.javalin.plugin.openapi.annotations.OpenApiResponse;

import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.google.common.flogger.FluentLogger;
import javax.servlet.http.HttpServletResponse;
import org.jooq.DSLContext;

public class ParametersController implements CrudHandler {
private static final Logger logger = Logger.getLogger(ParametersController.class.getName());
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
private final MetricRegistry metrics;

private final Histogram requestResultSize;
Expand Down Expand Up @@ -131,7 +130,7 @@ public void getAll(Context ctx) {
requestResultSize.update(results.length());
} catch (Exception ex) {
CdaError re = new CdaError("Failed to process request");
logger.log(Level.SEVERE, re.toString(), ex);
logger.atSevere().withCause(ex).log("%s", re);
ctx.status(HttpServletResponse.SC_INTERNAL_SERVER_ERROR).json(re);
}
}
Expand Down
13 changes: 5 additions & 8 deletions cwms-data-api/src/main/java/cwms/cda/api/PoolController.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@
import io.javalin.plugin.openapi.annotations.OpenApiContent;
import io.javalin.plugin.openapi.annotations.OpenApiParam;
import io.javalin.plugin.openapi.annotations.OpenApiResponse;
import java.util.logging.Logger;
import com.google.common.flogger.FluentLogger;
import javax.servlet.http.HttpServletResponse;
import org.jetbrains.annotations.NotNull;
import org.jooq.DSLContext;

public class PoolController implements CrudHandler {
public static final Logger logger = Logger.getLogger(PoolController.class.getName());
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
private static final int defaultPageSize = 100;

private final MetricRegistry metrics;
Expand Down Expand Up @@ -99,7 +99,7 @@ private Timer.Context markAndTime(String subject) {
tags = {"Pools"})
@Override
public void getAll(@NotNull Context ctx) {
try (final Timer.Context timeContext = markAndTime(GET_ALL);){
try (final Timer.Context timeContext = markAndTime(GET_ALL)){
DSLContext dsl = getDslContext(ctx);

PoolDao dao = new PoolDao(dsl);
Expand Down Expand Up @@ -179,7 +179,7 @@ public void getAll(@NotNull Context ctx) {
description = "Retrieves requested Pool", tags = {"Pools"})
@Override
public void getOne(@NotNull Context ctx, @NotNull String poolId) {
try (final Timer.Context timeContext = markAndTime(GET_ONE);){
try (final Timer.Context timeContext = markAndTime(GET_ONE)){
DSLContext dsl = getDslContext(ctx);

PoolDao dao = new PoolDao(dsl);
Expand All @@ -206,10 +206,7 @@ public void getOne(@NotNull Context ctx, @NotNull String poolId) {

if (pool == null) {
CdaError re = new CdaError("Unable to find pool based on parameters given");
logger.info(() -> {
String fullUrl = ctx.fullUrl();
return re + System.lineSeparator() + "for request " + fullUrl;
});
logger.atInfo().log("%s%nfor request %s", re, ctx.fullUrl());
ctx.status(HttpServletResponse.SC_NOT_FOUND).json(re);
} else {
String formatHeader = ctx.header(Header.ACCEPT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@
import io.javalin.plugin.openapi.annotations.OpenApiParam;
import io.javalin.plugin.openapi.annotations.OpenApiRequestBody;
import io.javalin.plugin.openapi.annotations.OpenApiResponse;
import java.util.logging.Logger;
import com.google.common.flogger.FluentLogger;
import javax.servlet.http.HttpServletResponse;
import org.jetbrains.annotations.NotNull;
import org.jooq.DSLContext;

public class ProjectController implements CrudHandler {
public static final Logger logger = Logger.getLogger(ProjectController.class.getName());
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
private static final int DEFAULT_PAGE_SIZE = 100;
public static final String TAG = "Projects";

Expand Down Expand Up @@ -177,10 +177,7 @@ public void getOne(@NotNull Context ctx, @NotNull String name) {

if (project == null) {
CdaError re = new CdaError("Unable to find Project based on parameters given");
logger.info(() -> {
String fullUrl = ctx.fullUrl();
return re + System.lineSeparator() + "for request " + fullUrl;
});
logger.atInfo().log("%s%nfor request %s", re, ctx.fullUrl());
ctx.status(HttpServletResponse.SC_NOT_FOUND).json(re);
} else {
String formatHeader = ctx.header(Header.ACCEPT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,15 @@

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.google.common.flogger.FluentLogger;

import static com.codahale.metrics.MetricRegistry.name;
import static cwms.cda.api.Controllers.*;
import static cwms.cda.data.dao.JooqDao.getDslContext;


public class SpecifiedLevelController implements CrudHandler {
private static final Logger logger = Logger.getLogger(SpecifiedLevelController.class.getName());
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
private static final String TAG = "Levels";
private final MetricRegistry metrics;

Expand Down Expand Up @@ -114,7 +113,7 @@ public void getAll(Context ctx) {
} catch (Exception ex) {
CdaError re =
new CdaError("Failed to process request: " + ex.getLocalizedMessage());
logger.log(Level.SEVERE, re.toString(), ex);
logger.atSevere().withCause(ex).log("%s", re);
ctx.status(HttpServletResponse.SC_INTERNAL_SERVER_ERROR).json(re);
}

Expand Down
Loading
Loading