Skip to content

Commit 5d4e0ac

Browse files
LarsEckartclaude
andcommitted
Implement separate logging for CLI and web modes with clean launcher scripts
- Create separate log files: logs/application-cli.log and logs/application-web.log - Add mode-specific system properties in CliApplication and WebApplication entry points - Configure Logback with time-based rolling policy and size limits - Suppress verbose Logback status messages for clean CLI experience - Create cli-app.sh launcher script for clean CLI interface (no Gradle noise) - Update dev-server.sh to use web-specific log file - Enable stdin for Gradle run task to support interactive CLI mode - Update all documentation (README.md, Agent.md, CLAUDE.md) with new commands 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent fa219cb commit 5d4e0ac

File tree

9 files changed

+140
-50
lines changed

9 files changed

+140
-50
lines changed

Agent.md

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,37 @@
11
# Code Editing Agent Java
22

33
## Commands
4+
5+
### CLI Mode
6+
- **Start CLI**: `./cli-app.sh` (builds and runs interactively)
7+
- **View CLI logs**: `tail -f logs/application-cli.log`
8+
9+
### Web Mode
10+
- **Start dev server**: `./dev-server.sh start` (with hot reloading)
11+
- **Stop dev server**: `./dev-server.sh stop`
12+
- **View web logs**: `./dev-server.sh logs`
13+
14+
### Build & Test
415
- **Build**: `./gradlew build` (includes fatJar creation)
516
- **Test**: `./run_tests.sh` (runs tests with formatted output)
617
- **Single test**: `./gradlew test --tests "ClassName"`
7-
- **Run CLI mode**: `./gradlew run` (default)
8-
- **Run Web mode**: `./gradlew run -Dapp.mode=web`
918
- **Clean**: `./gradlew clean`
1019

20+
## Logging
21+
22+
- **CLI logs**: `logs/application-cli.log` (separate file for CLI mode)
23+
- **Web logs**: `logs/application-web.log` (separate file for web mode)
24+
- **Log rotation**: Daily rotation with 30-day retention and 100MB size cap
25+
- **Clean startup**: No verbose Logback configuration messages in CLI mode
26+
1127
## Development Server
12-
- **Start dev server**: `./dev-server.sh start` (web mode with hot reloading)
13-
- **Stop dev server**: `./dev-server.sh stop`
14-
- **Restart dev server**: `./dev-server.sh restart` (needed for static file changes)
15-
- **Check status**: `./dev-server.sh status`
16-
- **View logs**: `./dev-server.sh logs`
28+
29+
For web development with hot reloading:
30+
- **Start**: `./dev-server.sh start` (web mode with hot reloading)
31+
- **Stop**: `./dev-server.sh stop`
32+
- **Restart**: `./dev-server.sh restart` (needed for static file changes)
33+
- **Status**: `./dev-server.sh status`
34+
- **Logs**: `./dev-server.sh logs`
1735

1836
**Note**: Hot reloading works for Java code changes. Static files (HTML, CSS, JS) in `src/main/resources/static/` require being "built" (copied to classpath) to trigger live reload - when running from command line with Gradle, this typically requires a server restart to see changes.
1937

CLAUDE.md

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,51 @@ This is a multi-module Gradle project with Kotlin DSL:
1717

1818
## Build Commands
1919

20+
### CLI Mode
21+
- **Start CLI**: `./cli-app.sh` (builds and runs interactively)
22+
- **View CLI logs**: `tail -f logs/application-cli.log`
23+
24+
### Web Mode
25+
- **Start dev server**: `./dev-server.sh start` (with hot reloading)
26+
- **Stop dev server**: `./dev-server.sh stop`
27+
- **View web logs**: `./dev-server.sh logs`
28+
29+
### Build & Test
2030
- **Build**: `./gradlew build` (includes fatJar creation)
2131
- **Test**: `./run_tests.sh` (runs tests with formatted output)
2232
- **Single test**: `./gradlew test --tests "ClassName"`
23-
- **Run CLI mode**: `./gradlew run` (default)
24-
- **Run Web mode**: `./gradlew run -Dapp.mode=web`
2533
- **Clean**: `./gradlew clean`
2634

35+
## Logging Configuration
36+
37+
### Separate Log Files
38+
- **CLI Mode**: `logs/application-cli.log`
39+
- **Web Mode**: `logs/application-web.log`
40+
- **Log Rotation**: Daily rotation with 30-day retention and 100MB total size cap
41+
- **Clean Output**: Logback status messages suppressed in CLI mode for clean user experience
42+
43+
### Configuration Details
44+
- **Logback config**: `app/src/main/resources/logback.xml`
45+
- **Mode detection**: Uses `app.mode` system property (set automatically by application entry points)
46+
- **Pattern**: `%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n`
47+
- **Log levels**: INFO for application, DEBUG for ConversationService, WARN for Spring/external libs
48+
2749
## Development Server
2850

29-
For development with hot reloading, use the provided development script:
51+
For web development with hot reloading:
3052

31-
- **Start dev server**: `./dev-server.sh start` (starts web mode with hot reloading)
32-
- **Stop dev server**: `./dev-server.sh stop`
33-
- **Restart dev server**: `./dev-server.sh restart`
34-
- **Check status**: `./dev-server.sh status`
35-
- **View logs**: `./dev-server.sh logs`
53+
- **Start**: `./dev-server.sh start` (starts web mode with hot reloading)
54+
- **Stop**: `./dev-server.sh stop`
55+
- **Restart**: `./dev-server.sh restart`
56+
- **Status**: `./dev-server.sh status`
57+
- **Logs**: `./dev-server.sh logs`
3658

3759
The development server includes:
3860
- **Automatic restart** when Java classes change
3961
- **Live reload** for static resources and templates (after build)
4062
- **Development configuration** with disabled caching
4163
- **Background process management** with PID tracking
64+
- **Logs to**: `logs/application-web.log`
4265

4366
**Note**: Hot reloading works for Java code changes. Static files (HTML, CSS, JS) in `src/main/resources/static/` require being "built" (copied to classpath) to trigger live reload - when running from command line with Gradle, this typically requires a server restart to see changes.
4467

@@ -68,15 +91,17 @@ The application supports two modes:
6891
### Key Dependencies
6992

7093
- **Anthropic Java SDK**: `com.anthropic:anthropic-java:2.0.0`
71-
- **Spring Boot**: `3.4.6` (for web mode)
72-
- **Java 21**: Required runtime version
94+
- **Spring Boot**: `3.5.0` (for web mode)
95+
- **Java 24**: Required runtime version
7396
- **JUnit 5**: For testing
7497

7598
### Configuration
7699

77-
- Set `ANTHROPIC_API_KEY` environment variable for API access
100+
- Set `code_editing_agent_api_key` environment variable for API access
78101
- Main class: `com.larseckart.App`
79-
- Uses Claude 3.5 Haiku model by default (configurable in `Client.java:66`)
102+
- Uses Claude 3.5 Haiku model by default (configurable in `ConversationService.java`)
103+
- **CLI Mode**: Set by `CliApplication.main()` with `System.setProperty("app.mode", "cli")`
104+
- **Web Mode**: Set by `WebApplication.main()` with `System.setProperty("app.mode", "web")`
80105

81106
### Code Style
82107

README.md

Lines changed: 39 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,45 +7,47 @@ This application demonstrates clean architecture principles and provides both CL
77

88
### Project Statistics
99

10-
- **Total Commits**: 55
11-
- **AI-Assisted Commits**: 36 (65.45%)
12-
- **Total Lines Added**: 7258
13-
- **AI-Assisted Lines Added**: 5588 (76.99%)
14-
- **Total Lines Changed**: 10821
15-
- **AI-Assisted Lines Changed**: 8418 (77.79%)
10+
- **Total Commits**: 56
11+
- **AI-Assisted Commits**: 37 (66.07%)
12+
- **Total Lines Added**: 7290
13+
- **AI-Assisted Lines Added**: 5620 (77.09%)
14+
- **Total Lines Changed**: 10876
15+
- **AI-Assisted Lines Changed**: 8473 (77.91%)
1616

1717
### Breakdown by AI Assistant
1818

1919
#### Claude Code
2020

21-
- **Commits**: 30 (54.55%)
21+
- **Commits**: 30 (53.57%)
2222
- **Lines Added**: 4941
2323
- **Lines Deleted**: 2307
24-
- **Lines Changed**: 7248 (66.98%)
24+
- **Lines Changed**: 7248 (66.64%)
2525

2626
#### Amp
2727

28-
- **Commits**: 4 (7.27%)
29-
- **Lines Added**: 576
30-
- **Lines Deleted**: 449
31-
- **Lines Changed**: 1025 (9.47%)
28+
- **Commits**: 5 (8.93%)
29+
- **Lines Added**: 608
30+
- **Lines Deleted**: 472
31+
- **Lines Changed**: 1080 (9.93%)
3232

3333
#### GitHub Copilot
3434

35-
- **Commits**: 2 (3.64%)
35+
- **Commits**: 2 (3.57%)
3636
- **Lines Added**: 71
3737
- **Lines Deleted**: 74
38-
- **Lines Changed**: 145 (1.34%)
38+
- **Lines Changed**: 145 (1.33%)
3939

4040

4141
*Statistics are automatically updated on each commit.*
4242

4343
## Features
4444

4545
- **Dual Interface Support**: Run as a command-line application or web server
46-
- **File Operations**: Built-in tools for reading, editing, and listing files
46+
- **File Operations**: Built-in tools for reading, editing, and listing files (CLI mode only)
4747
- **Clean Architecture**: Hexagonal architecture with clear separation of concerns
4848
- **Hot Reloading**: Development server with automatic restart and live reload
49+
- **Separate Logging**: Mode-specific log files (CLI: `logs/application-cli.log`, Web: `logs/application-web.log`)
50+
- **Simple Launchers**: Clean scripts for both CLI (`./cli-app.sh`) and web (`./dev-server.sh`) modes
4951
- **Comprehensive Testing**: Full test suite with JUnit 5
5052

5153
## Prerequisites
@@ -91,12 +93,12 @@ To automatically update AI contribution statistics in the README:
9193

9294
#### CLI Mode (Default)
9395
```bash
94-
./gradlew run
96+
./cli-app.sh
9597
```
9698

9799
#### Web Mode
98100
```bash
99-
./gradlew run -Dapp.mode=web
101+
./dev-server.sh start
100102
```
101103

102104
Then open http://localhost:8080 in your browser to access the chat interface.
@@ -136,6 +138,16 @@ For active development with hot reloading:
136138

137139
### Project Commands
138140

141+
#### CLI Mode
142+
- **Start CLI**: `./cli-app.sh` (builds and runs interactively)
143+
- **View CLI logs**: `tail -f logs/application-cli.log`
144+
145+
#### Web Mode
146+
- **Start dev server**: `./dev-server.sh start` (with hot reloading)
147+
- **Stop dev server**: `./dev-server.sh stop`
148+
- **View web logs**: `./dev-server.sh logs`
149+
150+
#### Build & Test
139151
- **Build**: `./gradlew build` (includes fatJar creation)
140152
- **Test**: `./run_tests.sh` (runs tests with formatted output)
141153
- **Clean**: `./gradlew clean`
@@ -200,16 +212,19 @@ app/src/main/java/com/larseckart/
200212

201213
### CLI Mode
202214
```bash
203-
$ ./gradlew run
204-
> Hello! How can I help you today?
205-
User: Can you read the contents of my config file?
206-
Claude: I can help you read a file. What's the path to your config file?
207-
User: ./app.properties
208-
Claude: [Reads and displays file contents]
215+
$ ./cli-app.sh
216+
Building application...
217+
Starting CLI application...
218+
219+
Chat with a LLM (use 'ctrl-c' to quit or press Enter on empty line)
220+
You: Can you read the contents of my config file?
221+
LarsGPT: I can help you read a file. What's the path to your config file?
222+
You: ./app.properties
223+
LarsGPT: [Reads and displays file contents]
209224
```
210225
211226
### Web Mode
212-
1. Start: `./gradlew run -Dapp.mode=web`
227+
1. Start: `./dev-server.sh start`
213228
2. Open: http://localhost:8080
214229
3. Chat through the web interface
215230

app/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ application {
3737

3838
tasks.named<JavaExec>("run") {
3939
systemProperties = System.getProperties().toMap() as Map<String, Any>
40+
standardInput = System.`in`
4041
}
4142

4243
// Set the Main-Class attribute in the jar manifest

app/src/main/java/com/larseckart/adapters/cli/CliApplication.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
public class CliApplication {
1515

1616
public static void main(String[] args) {
17+
System.setProperty("app.mode", "cli");
18+
1719
InputPort inputPort = new ConsoleInputAdapter();
1820
OutputPort outputPort = new ConsoleOutputAdapter();
1921

app/src/main/java/com/larseckart/adapters/web/WebApplication.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
public class WebApplication {
1212

1313
public static void main(String[] args) {
14+
System.setProperty("app.mode", "web");
1415
SpringApplication.run(WebApplication.class, args);
1516
}
1617

app/src/main/resources/logback.xml

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<configuration>
2+
<configuration debug="false">
33

4-
<!-- Define log file location -->
5-
<property name="LOG_FILE" value="${LOG_FILE:-logs/application.log}"/>
4+
<!-- Disable status messages -->
5+
<statusListener class="ch.qos.logback.core.status.NopStatusListener" />
6+
7+
<!-- Define log file location based on application mode -->
8+
<property name="APP_MODE" value="${app.mode:-cli}"/>
9+
<property name="LOG_FILE" value="logs/application-${APP_MODE}.log"/>
610
<property name="LOG_PATTERN" value="%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n"/>
711

812
<!-- Console appender for CLI mode -->
@@ -12,10 +16,17 @@
1216
</encoder>
1317
</appender>
1418

15-
<!-- Simple file appender that overwrites on each session -->
16-
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
19+
<!-- Rolling file appender to preserve log history -->
20+
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
1721
<file>${LOG_FILE}</file>
18-
<append>false</append>
22+
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
23+
<fileNamePattern>logs/application-${APP_MODE}.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
24+
<maxHistory>30</maxHistory>
25+
<totalSizeCap>100MB</totalSizeCap>
26+
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
27+
<maxFileSize>10MB</maxFileSize>
28+
</timeBasedFileNamingAndTriggeringPolicy>
29+
</rollingPolicy>
1930
<encoder>
2031
<pattern>${LOG_PATTERN}</pattern>
2132
</encoder>

cli-app.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
3+
# CLI application launcher
4+
# Usage: ./cli-app.sh
5+
6+
./gradlew build -q > /dev/null 2>&1
7+
8+
if [ $? -ne 0 ]; then
9+
echo "Build failed. Running build with output to show errors:"
10+
./gradlew build
11+
exit 1
12+
fi
13+
14+
echo ""
15+
16+
# Start the CLI application using the fat JAR (clean interface)
17+
java -Dapp.mode=cli -jar app/build/libs/app-all.jar

dev-server.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# Usage: ./dev-server.sh [start|stop|restart|status]
55

66
PID_FILE=".dev-server.pid"
7-
LOG_FILE="dev-server.log"
7+
LOG_FILE="logs/application-web.log"
88

99
start_server() {
1010
if [ -f "$PID_FILE" ]; then

0 commit comments

Comments
 (0)