comparison seobeo/LOGGING.md @ 96:70401cf61e97

[Seobeo] Added logging.
author June Park <parkjune1995@gmail.com>
date Fri, 02 Jan 2026 19:16:17 -0800
parents
children
comparison
equal deleted inserted replaced
95:b51f8cce9170 96:70401cf61e97
1 # Seobeo Logging System
2
3 ## Overview
4
5 All `printf` statements in the seobeo library have been replaced with `Seobeo_Log()` calls for consistent, level-based logging with optional debug mode.
6
7 ## Log Levels
8
9 ```c
10 typedef enum {
11 SEOBEO_INFO = 0, // General information (server start, mode, etc.)
12 SEOBEO_WARNING, // Warnings (SSL not compiled, etc.)
13 SEOBEO_ERROR, // Errors (allocation failures, connection errors, etc.)
14 SEOBEO_DEBUG, // Debug messages (only shown in development mode)
15 } Seobeo_Log_Level;
16 ```
17
18 ## Usage
19
20 ```c
21 Seobeo_Log(SEOBEO_INFO, "Listening on port %s\n", port);
22 Seobeo_Log(SEOBEO_ERROR, "Failed to allocate %zu bytes\n", size);
23 Seobeo_Log(SEOBEO_DEBUG, "Request line (first %zu bytes)\n", len);
24 ```
25
26 ## Debug Mode Control
27
28 Debug logs are controlled by the `SEOBEO_ENABLE_DEBUG` macro:
29
30 - **Production builds**: Debug logs are disabled (not compiled in)
31 - **Development builds**: Debug logs are enabled via `-DSEOBEO_ENABLE_DEBUG`
32
33 ## Build Targets
34
35 ### Seobeo Library
36
37 #### Production (No Debug Logs)
38 ```bash
39 # macOS
40 //seobeo:seobeo_server_macos
41
42 # Linux
43 //seobeo:seobeo_server_linux
44
45 # Platform-agnostic alias
46 //seobeo:seobeo_server
47 ```
48
49 #### Development (With Debug Logs)
50 ```bash
51 # macOS
52 //seobeo:seobeo_server_macos_dev
53
54 # Linux
55 //seobeo:seobeo_server_linux_dev
56
57 # Platform-agnostic alias
58 //seobeo:seobeo_server_dev
59 ```
60
61 ### MrJuneJune Server
62
63 #### Production Build
64 ```bash
65 # Build
66 bazel build //mrjunejune:mrjunejune_server
67
68 # Run
69 bazel run //mrjunejune:mrjunejune_server
70
71 # Bundle (for deployment)
72 bazel build //mrjunejune:mrjunejune_server_bundle
73 ```
74
75 #### Development Build (With Debug Logs)
76 ```bash
77 # Build
78 bazel build //mrjunejune:mrjunejune_server_dev
79
80 # Run
81 bazel run //mrjunejune:mrjunejune_server_dev
82
83 # Bundle
84 bazel build //mrjunejune:mrjunejune_server_dev_bundle
85 ```
86
87 ## Log Output Format
88
89 All logs are prefixed with their level:
90
91 ```
92 [INFO] Listening on port 6969
93 [INFO] Server mode: EDGE
94 [ERROR] Failed to allocate 1024 bytes for body
95 [DEBUG] Request line (first 200 bytes)
96 [DEBUG] sscanf returned 3 (method='GET', path='/', version='HTTP/1.1')
97 ```
98
99 ## Changes Summary
100
101 ### Files Modified
102
103 1. **seobeo/s_web.c**
104 - Replaced 26 printf statements with Seobeo_Log
105 - Updated logging to use appropriate levels (INFO, ERROR, DEBUG)
106
107 2. **seobeo/s_linux_network.c**
108 - Replaced 10 printf statements with Seobeo_Log
109 - Added proper error and debug logging for network operations
110
111 3. **seobeo/s_ssl.c**
112 - Replaced 5 printf/fprintf statements with Seobeo_Log
113 - SSL errors now use SEOBEO_ERROR level
114 - SSL info uses SEOBEO_INFO level
115
116 4. **seobeo/BUILD**
117 - Added `seobeo_server_dev` alias for development builds
118 - Added `seobeo_server_macos_dev` with `SEOBEO_ENABLE_DEBUG`
119 - Added `seobeo_server_linux_dev` with `SEOBEO_ENABLE_DEBUG`
120
121 5. **mrjunejune/BUILD**
122 - Added `mrjunejune_server_dev` binary target
123 - Added `mrjunejune_server_dev_bundle` for development deployment
124
125 ## Benefits
126
127 1. **Cleaner Production Logs**: Debug messages don't clutter production output
128 2. **Better Debugging**: Enable verbose logging during development
129 3. **Consistent Format**: All logs follow the same `[LEVEL] message` format
130 4. **Conditional Compilation**: Debug code is completely removed from production builds (zero runtime overhead)
131 5. **Easy Toggle**: Switch between dev and prod with different build targets
132
133 ## Examples
134
135 ### Running in Development Mode
136 ```bash
137 $ bazel run //mrjunejune:mrjunejune_server_dev
138 [INFO] Listening on port 6969
139 [INFO] Server mode: EDGE
140 [DEBUG] Request line (first 30 bytes)
141 [DEBUG] sscanf returned 3 (method='GET', path='/', version='HTTP/1.1')
142 [DEBUG] Allocating method_copy
143 [DEBUG] Allocating version_copy
144 [DEBUG] Map now has 2 entries
145 [DEBUG] File path: /index.html
146 Body Size: 1234
147 [DEBUG] Request handled successfully
148 ```
149
150 ### Running in Production Mode
151 ```bash
152 $ bazel run //mrjunejune:mrjunejune_server
153 [INFO] Listening on port 6969
154 [INFO] Server mode: EDGE
155 ```
156
157 Notice that debug messages are completely absent in production mode!