Skip to content

Commit 8db85d3

Browse files
Add logging configuration support and clarify documentation
Introduce `log-level` and `show-detailed-logs` options in the CLI for flexible logging configuration. Update `utils/logger.py` to align with renamed environment variables and enhance validation in `InputsCollector.py`. Revise README to include instructions for using the new logging settings.
1 parent 1336459 commit 8db85d3

File tree

4 files changed

+39
-5
lines changed

4 files changed

+39
-5
lines changed

README.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,10 @@ python3 main.py --mode custom --problems two-sum
8787

8888
## Configurations
8989
Squidleet uses a `LEETCODE_SESSION` cookie for authentication. Setting the `LEETCODE_SESSION` environment variable is necessary for all operations, including fetching and submitting problems.
90-
Squidleet uses a `LEETCODE_SESSION` cookie for authentication. You will need to set the `LEETCODE_SESSION` value as an environment variable or pass it as an argument when running the script.
9190

92-
### Extracting `LEETCODE_SESSION` 🍪 Cookie
91+
### `LEETCODE_SESSION` Cookie
92+
93+
#### Extracting `LEETCODE_SESSION` 🍪 Cookie
9394

9495
To obtain the `LEETCODE_SESSION` cookie, follow these steps:
9596

@@ -104,6 +105,19 @@ Set the cookie value as an environment variable `.env`:
104105
LEETCODE_SESSION=<your_session_cookie>
105106
```
106107

108+
### Logs
109+
110+
Squidleet exposes two environment variables for logging:
111+
112+
- `LOG_LEVEL`: Set the log level for the application. Default is `INFO`.
113+
- `SHOW_DETAILED_LOGS`: Enable detailed logs for debugging purposes. Default is `False`.
114+
115+
These can also be set via arguments in the CLI:
116+
117+
```bash
118+
python3 main.py --mode daily --log-level INFO --show-detailed-logs
119+
```
120+
107121
## License
108122

109123
Squidleet is open-sourced under the MIT License. See the `LICENSE` file for more details.

services/CommandParser.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,18 @@ def parse():
3939
parser.add_argument(
4040
"--open-in-browser", action="store_true", help="Open the problem in a browser"
4141
)
42+
parser.add_argument(
43+
"--log-level",
44+
type=str,
45+
choices=["DEBUG", "INFO", "WARN", "ERROR"],
46+
help="Log level",
47+
default="INFO",
48+
)
49+
parser.add_argument(
50+
"--show-detailed-logs",
51+
action="store_true",
52+
help="Show timestamp and log level in logs",
53+
default=False,
54+
)
4255

4356
return vars(parser.parse_args())

services/InputsCollector.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ def collect(cli_options):
1313
elif practice_mode == "custom":
1414
problems = cli_options.get("problems", "").split(",")
1515

16+
log_level = cli_options.get("log_level", "INFO")
1617
study_plan = cli_options.get("study_plan", "top-interview-150")
1718
language = cli_options.get("language", "python")
1819
time_limit = cli_options.get("time_limit", 45)
@@ -28,6 +29,7 @@ def collect(cli_options):
2829
"time_limit": time_limit,
2930
"editor": editor,
3031
"open_in_browser": open_in_browser,
32+
"log_level": log_level,
3133
}
3234

3335
_validate(inputs)
@@ -65,3 +67,9 @@ def _validate(inputs):
6567
valid_editors = ["default", "code", "nvim", "nano", "vim"]
6668
if inputs["editor"] not in valid_editors:
6769
raise ValueError(f"Invalid editor. Use one of: {', '.join(valid_editors)}")
70+
71+
valid_log_levels = ["DEBUG", "INFO", "WARN", "ERROR"]
72+
if inputs["log_level"] not in valid_log_levels:
73+
raise ValueError(
74+
f"Invalid log level. Use one of: {', '.join(valid_log_levels)}"
75+
)

utils/logger.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,11 @@ class LogLevel:
2525
def log(message: str, level: str = LogLevel.INFO):
2626
# Get the configured logging level or default to INFO if not set
2727
configured_level = os.getenv("LOGGING_LEVEL", LogLevel.INFO)
28-
show_log_details = os.getenv("SHOW_LOG_DETAILS", "False").lower() == "true"
28+
show_detailed_logs = os.getenv("SHOW_DETAILED_LOGS", "False").lower() == "true"
2929

3030
# Only log messages with a sufficient level
3131
if LOG_LEVEL_PRIORITY.get(level, 0) >= LOG_LEVEL_PRIORITY.get(configured_level, 0):
32-
# Include timestamp/level details if SHOW_LOG_DETAILS is enabled
33-
if show_log_details:
32+
if show_detailed_logs:
3433
timestamp = datetime.datetime.now().isoformat()
3534
if level == LogLevel.DEBUG:
3635
print(f"🐞 [{timestamp}] [{level}] {message}")

0 commit comments

Comments
 (0)