diff --git a/.idea/dataSources.xml b/.idea/dataSources.xml
new file mode 100644
index 0000000..cbb7473
--- /dev/null
+++ b/.idea/dataSources.xml
@@ -0,0 +1,12 @@
+
+
+
+
+ sqlite.xerial
+ true
+ org.sqlite.JDBC
+ jdbc:sqlite:$PROJECT_DIR$/data/loghunter.db
+ $ProjectFileDir$
+
+
+
\ No newline at end of file
diff --git a/.idea/data_source_mapping.xml b/.idea/data_source_mapping.xml
new file mode 100644
index 0000000..575a094
--- /dev/null
+++ b/.idea/data_source_mapping.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/log-hunter.iml b/.idea/log-hunter.iml
index d6ebd48..c956989 100644
--- a/.idea/log-hunter.iml
+++ b/.idea/log-hunter.iml
@@ -1,7 +1,6 @@
-
-
-
+
+
diff --git a/.idea/modules.xml b/.idea/modules.xml
index 2126e1e..ba329d2 100644
--- a/.idea/modules.xml
+++ b/.idea/modules.xml
@@ -2,7 +2,7 @@
-
+
\ No newline at end of file
diff --git a/src/main/java/research/loghunter/config/DatabaseConfig.java b/src/main/java/research/loghunter/config/DatabaseConfig.java
new file mode 100644
index 0000000..0f508ed
--- /dev/null
+++ b/src/main/java/research/loghunter/config/DatabaseConfig.java
@@ -0,0 +1,61 @@
+package research.loghunter.config;
+
+import jakarta.annotation.PostConstruct;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Configuration;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+/**
+ * 데이터베이스 및 앱 디렉토리 초기화 설정
+ *
+ * 앱 실행 시 필요한 디렉토리를 자동으로 생성합니다.
+ * - ~/.loghunter/data/ : SQLite DB 파일
+ * - ~/.loghunter/exports/ : 내보내기 파일
+ */
+@Slf4j
+@Configuration
+public class DatabaseConfig {
+
+ @Value("${app.base-path}")
+ private String basePath;
+
+ @Value("${app.export.path}")
+ private String exportPath;
+
+ @PostConstruct
+ public void init() {
+ try {
+ // 기본 디렉토리 생성
+ Path baseDir = Paths.get(basePath);
+ createDirectoryIfNotExists(baseDir);
+
+ // 데이터 디렉토리 생성
+ Path dataDir = baseDir.resolve("data");
+ createDirectoryIfNotExists(dataDir);
+
+ // 내보내기 디렉토리 생성
+ Path exportsDir = Paths.get(exportPath);
+ createDirectoryIfNotExists(exportsDir);
+
+ log.info("LogHunter 디렉토리 초기화 완료: {}", basePath);
+ log.info(" - 데이터: {}", dataDir);
+ log.info(" - 내보내기: {}", exportsDir);
+
+ } catch (IOException e) {
+ log.error("디렉토리 생성 실패: {}", e.getMessage());
+ throw new RuntimeException("LogHunter 디렉토리 초기화 실패", e);
+ }
+ }
+
+ private void createDirectoryIfNotExists(Path dir) throws IOException {
+ if (!Files.exists(dir)) {
+ Files.createDirectories(dir);
+ log.info("디렉토리 생성: {}", dir);
+ }
+ }
+}
diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml
index ecfc827..10d44d7 100644
--- a/src/main/resources/application.yml
+++ b/src/main/resources/application.yml
@@ -6,7 +6,7 @@ spring:
name: log-hunter
datasource:
- url: jdbc:sqlite:./data/loghunter.db
+ url: jdbc:sqlite:${user.home}/.loghunter/data/loghunter.db
driver-class-name: org.sqlite.JDBC
jpa:
@@ -28,7 +28,8 @@ spring:
# 앱 설정
app:
+ base-path: ${user.home}/.loghunter
crypto:
key: ${LOGHUNTER_CRYPTO_KEY:LogHunterDefaultKey32Bytes!!}
export:
- path: ./exports
+ path: ${user.home}/.loghunter/exports
diff --git a/start.sh b/start.sh
old mode 100755
new mode 100644
index 270f928..aac105f
--- a/start.sh
+++ b/start.sh
@@ -6,25 +6,40 @@ cd "$(dirname "$0")"
export JAVA_HOME="/Users/coziny/Library/Java/JavaVirtualMachines/temurin-21.0.9/Contents/Home"
export PATH="$JAVA_HOME/bin:$PATH"
+# 앱 데이터 경로
+LOGHUNTER_HOME="$HOME/.loghunter"
+
echo "=========================================="
echo " LogHunter 시작"
echo "=========================================="
echo " Java: $(java -version 2>&1 | head -1)"
+echo " Data: $LOGHUNTER_HOME"
echo "=========================================="
# 포트 정리
-echo "[1/4] 8080 포트 정리..."
+echo "[1/5] 8080 포트 정리..."
lsof -ti:8080 | xargs kill -9 2>/dev/null
+# 기존 DB 마이그레이션 (최초 1회)
+echo "[2/5] 데이터 디렉토리 확인..."
+if [ -f "./data/loghunter.db" ] && [ ! -f "$LOGHUNTER_HOME/data/loghunter.db" ]; then
+ echo " → 기존 DB 파일 발견, 새 위치로 마이그레이션..."
+ mkdir -p "$LOGHUNTER_HOME/data"
+ cp "./data/loghunter.db" "$LOGHUNTER_HOME/data/loghunter.db"
+ echo " ✓ 마이그레이션 완료: $LOGHUNTER_HOME/data/loghunter.db"
+else
+ echo " ✓ 데이터 경로 준비됨"
+fi
+
# 프론트엔드 빌드
-echo "[2/4] 프론트엔드 빌드..."
+echo "[3/5] 프론트엔드 빌드..."
cd frontend
npm install --include=dev
npm run build
cd ..
# static 폴더 확인
-echo "[3/4] 빌드 결과 확인..."
+echo "[4/5] 빌드 결과 확인..."
if [ -f "src/main/resources/static/index.html" ]; then
echo " ✓ index.html 확인됨"
else
@@ -33,10 +48,11 @@ else
fi
# 서버 실행
-echo "[4/4] 서버 실행..."
+echo "[5/5] 서버 실행..."
echo ""
echo "=========================================="
echo " http://localhost:8080"
+echo " DB: $LOGHUNTER_HOME/data/loghunter.db"
echo " 종료: Ctrl+C"
echo "=========================================="
echo ""