JatsTheAIGen commited on
Commit
df93424
·
1 Parent(s): 3059e9a

fix: Resolve permission error for log file in Docker container

Browse files

- Change log file location from /app/app.log to /tmp/app.log (writable in containers)
- Add error handling to gracefully fallback to console-only logging if file logging fails
- Update test files (test_logging.py, test_task_type_fix.py) with same fix
- Prevents PermissionError: [Errno 13] Permission denied crashes on startup

Files changed (3) hide show
  1. app.py +10 -4
  2. test_logging.py +10 -4
  3. test_task_type_fix.py +10 -4
app.py CHANGED
@@ -10,13 +10,19 @@ import time
10
  from datetime import datetime
11
 
12
  # Configure comprehensive logging
 
 
 
 
 
 
 
 
 
13
  logging.basicConfig(
14
  level=logging.INFO,
15
  format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
16
- handlers=[
17
- logging.StreamHandler(),
18
- logging.FileHandler('app.log')
19
- ]
20
  )
21
  logger = logging.getLogger(__name__)
22
 
 
10
  from datetime import datetime
11
 
12
  # Configure comprehensive logging
13
+ # Use /tmp for log file (writable in containers) with fallback to console-only
14
+ handlers = [logging.StreamHandler()]
15
+ try:
16
+ log_file = os.path.join('/tmp', 'app.log')
17
+ handlers.append(logging.FileHandler(log_file))
18
+ except (PermissionError, OSError) as e:
19
+ # Fallback to console-only logging if file logging fails
20
+ print(f"Warning: Could not create log file ({e}). Using console logging only.")
21
+
22
  logging.basicConfig(
23
  level=logging.INFO,
24
  format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
25
+ handlers=handlers
 
 
 
26
  )
27
  logger = logging.getLogger(__name__)
28
 
test_logging.py CHANGED
@@ -15,13 +15,19 @@ sys.path.insert(0, '.')
15
  sys.path.insert(0, 'src')
16
 
17
  # Configure logging to match the main application
 
 
 
 
 
 
 
 
 
18
  logging.basicConfig(
19
  level=logging.INFO,
20
  format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
21
- handlers=[
22
- logging.StreamHandler(),
23
- logging.FileHandler('test_logging.log')
24
- ]
25
  )
26
 
27
  logger = logging.getLogger(__name__)
 
15
  sys.path.insert(0, 'src')
16
 
17
  # Configure logging to match the main application
18
+ # Use /tmp for log file (writable in containers) with fallback to console-only
19
+ handlers = [logging.StreamHandler()]
20
+ try:
21
+ log_file = os.path.join('/tmp', 'test_logging.log')
22
+ handlers.append(logging.FileHandler(log_file))
23
+ except (PermissionError, OSError) as e:
24
+ # Fallback to console-only logging if file logging fails
25
+ print(f"Warning: Could not create log file ({e}). Using console logging only.")
26
+
27
  logging.basicConfig(
28
  level=logging.INFO,
29
  format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
30
+ handlers=handlers
 
 
 
31
  )
32
 
33
  logger = logging.getLogger(__name__)
test_task_type_fix.py CHANGED
@@ -14,13 +14,19 @@ sys.path.insert(0, '.')
14
  sys.path.insert(0, 'src')
15
 
16
  # Configure logging
 
 
 
 
 
 
 
 
 
17
  logging.basicConfig(
18
  level=logging.INFO,
19
  format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
20
- handlers=[
21
- logging.StreamHandler(),
22
- logging.FileHandler('test_task_type_fix.log')
23
- ]
24
  )
25
 
26
  logger = logging.getLogger(__name__)
 
14
  sys.path.insert(0, 'src')
15
 
16
  # Configure logging
17
+ # Use /tmp for log file (writable in containers) with fallback to console-only
18
+ handlers = [logging.StreamHandler()]
19
+ try:
20
+ log_file = os.path.join('/tmp', 'test_task_type_fix.log')
21
+ handlers.append(logging.FileHandler(log_file))
22
+ except (PermissionError, OSError) as e:
23
+ # Fallback to console-only logging if file logging fails
24
+ print(f"Warning: Could not create log file ({e}). Using console logging only.")
25
+
26
  logging.basicConfig(
27
  level=logging.INFO,
28
  format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
29
+ handlers=handlers
 
 
 
30
  )
31
 
32
  logger = logging.getLogger(__name__)