Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve logging #31

Merged
merged 2 commits into from
Dec 13, 2021
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
12 changes: 6 additions & 6 deletions src/main/java/io/seqera/tower/agent/Agent.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.Duration;
import java.util.Properties;
import java.util.concurrent.TimeUnit;
Expand All @@ -62,7 +61,7 @@
)
public class Agent implements Runnable {
public static final int HEARTBEAT_MINUTES_INTERVAL = 1;
private static Logger logger = LoggerFactory.getLogger(Agent.class);
private static final Logger logger = LoggerFactory.getLogger(Agent.class);

@Parameters(index = "0", paramLabel = "AGENT_CONNECTION_ID", description = "Agent connection ID to identify this agent.", arity = "1")
String agentKey;
Expand All @@ -76,7 +75,7 @@ public class Agent implements Runnable {
@Option(names = {"-w", "--work-dir"}, description = "Default path where the pipeline scratch data is stored. It can be changed when launching a pipeline from Tower [default: $HOME/work].", defaultValue = "${HOME}/work")
Path workDir;

private ApplicationContext ctx;
private final ApplicationContext ctx;
private AgentClientSocket agentClient;

Agent() {
Expand Down Expand Up @@ -139,7 +138,8 @@ private void connectTower() {
*/
private void execCommand(CommandRequest message) {
try {
logger.info("Execute: {}", message.getCommand());
logger.info("Executing request {}", message.getId());
logger.trace("REQUEST: {}", message);
Process process = new ProcessBuilder().command("sh", "-c", message.getCommand()).start();
int exitStatus = process.waitFor();
// read the stdout
Expand All @@ -154,9 +154,9 @@ private void execCommand(CommandRequest message) {

// send result
CommandResponse response = new CommandResponse(message.getId(), result.getBytes(), exitStatus);
logger.info("Sending response --> {}", response);
logger.info("Sending response {}'", response.getId());
logger.trace("RESPONSE: {}", response);
agentClient.send(response);
logger.info("Response sent");
} catch (Exception e) {
// send result
CommandResponse response = new CommandResponse(message.getId(), e.getMessage().getBytes(), -1);
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/io/seqera/tower/agent/AgentClientSocket.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ abstract class AgentClientSocket implements AutoCloseable {
void onOpen(WebSocketSession session) {
this.session = session;
this.openingTime = Instant.now();
logger.info("Client opened connection");
logger.info("Connection to Tower established");
logger.debug("Websocket session URL: {}", session.getRequestURI());
}

@OnMessage
Expand Down
4 changes: 1 addition & 3 deletions src/main/resources/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@

<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<withJansi>true</withJansi>
<!-- encoders are assigned the type
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
<encoder>
<pattern>%cyan(%d{HH:mm:ss.SSS}) %gray([%thread]) %highlight(%-5level) %magenta(%logger{36}) - %msg%n</pattern>
<pattern>%cyan(%d{HH:mm:ss.SSS}) %highlight(%-5level)- %msg%n</pattern>
</encoder>
</appender>

Expand Down