# Test 7: Simple Logging Test - Upload Commands

## Purpose
Verify that basic logging works in Container Runtime and appears in the event table before attempting complex import diagnostics.

## Step 1: Upload Simple Test File

```sql
-- Upload the simple logging test (no other files needed)
PUT file:///Users/mach071/Documents/collab/mymac80/spark/hello_world_tests/test_7_simple_logging.py @spark_streamlit_stage;
```

## Step 2: Verify Upload

```sql
-- Check files are uploaded
LIST @spark_streamlit_stage;
```

## Step 3: Create Simple Streamlit App

```sql
CREATE STREAMLIT FANSIFTER_APP_REPORTING.DEV_MMACHADO.spark_test_7_simple_logging
    ROOT_LOCATION = '@FANSIFTER_APP_REPORTING.DEV_MMACHADO.spark_streamlit_stage'
    MAIN_FILE = 'test_7_simple_logging.py'
    QUERY_WAREHOUSE = DEV_OWS_WH
    COMPUTE_POOL = spark_streamlit_pool
    EXTERNAL_ACCESS_INTEGRATIONS = (spark_external_access)
    COMMENT = 'Test 7: Simple logging verification for Container Runtime';
```

## Step 4: Test Logging

1. **Launch the Streamlit app** from Snowsight
2. **Click "Generate Test Logs"** button
3. **Optionally test import** with the second button
4. **Wait a moment** for logs to propagate

## Step 5: Verify Logs in Event Table

Execute these queries in order:

### 5a. Check if ANY records exist
```sql
SELECT COUNT(*) as total_records, record_type
FROM spark_event_table
GROUP BY record_type;
```

### 5b. Look for our specific logs
```sql
SELECT 
    timestamp,
    record_type,
    record,
    scope
FROM spark_event_table
WHERE record_type = 'LOG'
  AND scope:name::STRING = 'simple_logger'
ORDER BY timestamp DESC
LIMIT 10;
```

### 5c. If no logs, check what IS in the table
```sql
SELECT 
    timestamp,
    record_type,
    record,
    scope,
    resource_attributes
FROM spark_event_table
ORDER BY timestamp DESC
LIMIT 10;
```

### 5d. Verify event table configuration
```sql
-- Check event table exists
SHOW TABLES LIKE '%event%';

-- Check database log level
SHOW PARAMETERS LIKE 'LOG_LEVEL' IN DATABASE FANSIFTER_APP_REPORTING;

-- Check if account event table is set
SHOW PARAMETERS LIKE 'EVENT_TABLE' IN ACCOUNT;
```

## Expected Outcomes

### If Logging Works:
- Event table will contain LOG records with record_type = 'LOG'
- Scope will show logger name as 'simple_logger'
- Log messages will appear in record object

### If Logging Doesn't Work:
- Event table will be empty or missing LOG records
- May indicate event table configuration issue
- Need to troubleshoot Container Runtime logging setup

## Troubleshooting Steps

If no logs appear:

1. **Check account-level event table setting:**
```sql
-- This may need to be run by ACCOUNTADMIN
ALTER ACCOUNT SET EVENT_TABLE = FANSIFTER_APP_REPORTING.DEV_MMACHADO.spark_event_table;
```

2. **Verify database log level:**
```sql
ALTER DATABASE FANSIFTER_APP_REPORTING SET LOG_LEVEL = 'DEBUG';
```

3. **Check Container Runtime specific logging:**
- Container Runtime may handle logging differently
- May need to wait longer for log propagation
- Check Snowsight logs/monitoring for the Streamlit app

## Next Steps

- **If logs work:** Proceed with enhanced import diagnostics (Test 6)
- **If logs don't work:** Focus on event table configuration before import testing
- **Document findings:** Update knowledge base with Container Runtime logging patterns