001/*
002 * Copyright 2025 devteam@scivics-lab.com
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing,
011 * software distributed under the License is distributed on an
012 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
013 * either express or implied.  See the License for the
014 * specific language governing permissions and limitations
015 * under the License.
016 */
017
018package com.scivicslab.actoriac.log;
019
020import java.time.LocalDateTime;
021
022/**
023 * Represents a single log entry.
024 *
025 * @author devteam@scivics-lab.com
026 */
027public class LogEntry {
028    private final long id;
029    private final long sessionId;
030    private final LocalDateTime timestamp;
031    private final String nodeId;
032    private final String vertexName;
033    private final String actionName;
034    private final LogLevel level;
035    private final String message;
036    private final Integer exitCode;
037    private final Long durationMs;
038
039    public LogEntry(long id, long sessionId, LocalDateTime timestamp, String nodeId,
040                    String vertexName, String actionName, LogLevel level, String message,
041                    Integer exitCode, Long durationMs) {
042        this.id = id;
043        this.sessionId = sessionId;
044        this.timestamp = timestamp;
045        this.nodeId = nodeId;
046        this.vertexName = vertexName;
047        this.actionName = actionName;
048        this.level = level;
049        this.message = message;
050        this.exitCode = exitCode;
051        this.durationMs = durationMs;
052    }
053
054    public long getId() { return id; }
055    public long getSessionId() { return sessionId; }
056    public LocalDateTime getTimestamp() { return timestamp; }
057    public String getNodeId() { return nodeId; }
058    public String getVertexName() { return vertexName; }
059    public String getActionName() { return actionName; }
060    public LogLevel getLevel() { return level; }
061    public String getMessage() { return message; }
062    public Integer getExitCode() { return exitCode; }
063    public Long getDurationMs() { return durationMs; }
064
065    @Override
066    public String toString() {
067        StringBuilder sb = new StringBuilder();
068        sb.append("[").append(timestamp.toString().replace("T", " ")).append("] ");
069        sb.append(String.format("%-5s ", level));
070        if (vertexName != null) {
071            sb.append("[").append(vertexName);
072            if (actionName != null) {
073                sb.append(" -> ").append(actionName);
074            }
075            sb.append("] ");
076        }
077        sb.append(message);
078        if (exitCode != null && exitCode != 0) {
079            sb.append(" (exit=").append(exitCode).append(")");
080        }
081        if (durationMs != null) {
082            sb.append(" [").append(durationMs).append("ms]");
083        }
084        return sb.toString();
085    }
086}