Skip to content

Commit 5201571

Browse files
Enhance logging functionality to support console-only output option
1 parent 55de363 commit 5201571

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

v4n1_Trainer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212
# ---------------- INIT ----------------
1313
def init(config: TrainingConfig) -> dict:
1414
"""Initialize static, config-free resources (only once)."""
15-
log("Loading GPT-Neo tokenizer/model (static init)...", cfg=config)
15+
log("Loading GPT-Neo tokenizer/model (static init)...", cfg=config, only_console=True)
1616
gpt_tokenizer = AutoTokenizer.from_pretrained("EleutherAI/gpt-neo-1.3B")
1717
gpt_model = AutoModelForCausalLM.from_pretrained("EleutherAI/gpt-neo-1.3B")
1818
if gpt_tokenizer.pad_token is None:
1919
gpt_tokenizer.pad_token = gpt_tokenizer.eos_token
2020

21-
log("Loading MiniLM for embeddings (static init)...", cfg=config)
21+
log("Loading MiniLM for embeddings (static init)...", cfg=config, only_console=True)
2222
embed_model = SentenceTransformer("sentence-transformers/all-MiniLM-L6-v2")
2323

2424
return {

vulnscan/log.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@
33
from vulnscan.config import TrainingConfig
44

55

6-
def log(message: str, cfg: TrainingConfig, silent: bool = False):
6+
def log(message: str, cfg: TrainingConfig, silent: bool = False, only_console: bool = False):
7+
"""Log a message to console and log file."""
8+
if only_console and silent:
9+
return # nothing to do
710
if not silent:
811
print(message)
9-
with open(cfg.LOG_FILE, "a") as f:
10-
f.write(f"{datetime.now()} | {message}\n")
12+
if not only_console:
13+
with open(cfg.LOG_FILE, "a") as f:
14+
f.write(f"{datetime.now()} | {message}\n")

0 commit comments

Comments
 (0)