Skip to content
Merged
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 .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions .idea/runConfigurations/Demo.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cirrus-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<parent>
<groupId>ai.cirkl.oss</groupId>
<artifactId>Cirrus</artifactId>
<version>1.2.0</version>
<version>1.2.1</version>
</parent>

<artifactId>cirrus-api</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion cirrus-api/src/main/java/ai/cirkl/oss/api/Cirrus.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public Cirrus modify(final CirrusExtension... extensions) {
}

public Cirrus sensibleDefaults() {
return modify(new LoggingExtension(), new StaticFilesExtension(), new DefaultErrorsExtension());
return modify(new LoggingExtension(Level.INFO), new StaticFilesExtension(), new DefaultErrorsExtension());
}

public Cirrus routes(final Object controller) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.core.config.Configurator;

@SuppressWarnings("unused")
public final class LoggingExtension implements CirrusExtension {

private final Level level;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package ai.cirkl.oss.api.extension;

import ai.cirkl.oss.api.context.CirrusContext;
import ai.cirkl.oss.api.interfaces.CirrusExtension;
import ai.cirkl.oss.core.utils.net.CirrusHandler;

@SuppressWarnings("unused")
public class RequestLoggerExtension implements CirrusExtension {

public RequestLoggerExtension() {
}

@Override
public void apply(final CirrusContext context) {
CirrusHandler.logRequests = true;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
@FunctionalInterface
public interface CirrusExtension {

void apply(CirrusContext context);
void apply(final CirrusContext context);


}
2 changes: 1 addition & 1 deletion cirrus-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<parent>
<groupId>ai.cirkl.oss</groupId>
<artifactId>Cirrus</artifactId>
<version>1.2.0</version>
<version>1.2.1</version>
</parent>

<artifactId>cirrus-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public static String render(final String templateName, final Map<String, Object>

private static String loadTemplate(final String name) {
if(cacheEnabled && cache.containsKey(name)) {
logger.trace("Template loaded from cache: {}", name);
logger.debug("Template loaded from cache: {}", name);
return cache.get(name);
}

Expand All @@ -76,15 +76,15 @@ private static String loadTemplate(final String name) {
logger.debug("Template loaded from classpath: {}", name);
}
} catch(final IOException ioException) {
logger.trace("Could not load template from classpath: {}", name);
logger.error("Could not load template from classpath: {}", name);
}

if(content == null) {
try {
content = Files.readString(Path.of(templateDir, name));
logger.debug("Template loaded from filesystem: {}", name);
} catch(IOException e) {
logger.trace("Could not load template from filesystem: {}", name);
} catch(IOException ioException) {
logger.error("Could not load template from filesystem: {}", name);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,23 @@
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.handler.codec.http.*;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.config.Configurator;

import java.nio.charset.StandardCharsets;

public final class CirrusHandler extends ChannelInboundHandlerAdapter {
private static final Logger logger = LogManager.getLogger(CirrusHandler.class);
private final Router router;
public static boolean logRequests = false;

public CirrusHandler(final Router router) {
if(!logRequests) {
Configurator.setLevel(CirrusHandler.class, Level.OFF);
}

this.router = router;
}

Expand All @@ -58,13 +65,13 @@ public void channelRead(final ChannelHandlerContext ctx, final Object msg) {
final String path = decoder.path();
final HttpMethod method = HttpMethod.valueOf(nettyReq.method().name());

logger.debug("Incoming request: {} {}", method, path);
logger.info("Incoming request: {} {}", method, path);

final RouteMatch match = router.match(path, method);
ResponseContext responseContext = new ResponseContext();

if(match != null) {
logger.debug("Route matched: {}", match.routeAdapter().path());
logger.info("Route matched: {}", match.routeAdapter().path());
final RequestContext requestContext = new RequestContext(nettyReq, match.params());
try {
final Object result = match.routeAdapter().handler().handle(requestContext, responseContext);
Expand Down Expand Up @@ -130,4 +137,6 @@ public void exceptionCaught(final ChannelHandlerContext ctx, final Throwable cau
logger.error("Channel exception caught", cause);
ctx.close();
}


}
2 changes: 1 addition & 1 deletion example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<parent>
<groupId>ai.cirkl.oss</groupId>
<artifactId>Cirrus</artifactId>
<version>1.2.0</version>
<version>1.2.1</version>
</parent>

<artifactId>cirrus-example</artifactId>
Expand Down
3 changes: 0 additions & 3 deletions example/src/main/java/ai/cirkl/oss/example/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ public final class App {
private final List<User> users = new ArrayList<>();
private final AtomicInteger idCounter = new AtomicInteger(1);

//.modify(new LoggingExtension(),
// new DefaultErrorsExtension(),
// new StaticFilesExtension())
@SuppressWarnings("unused")
public static void run(final String[] args) {
new Cirrus()
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

<groupId>ai.cirkl.oss</groupId>
<artifactId>Cirrus</artifactId>
<version>1.2.0</version>
<version>1.2.1</version>
<packaging>pom</packaging>

<modules>
Expand Down