Week 2 : Initializing logs & Making Organize commands
I am a CS student learning and exploring this technology field and eagerness to build something.
One of the core design goals of SetFile is traceability.
Since SetFile automatically moves user files, it must be:
Auditable
Reversible
Transparent
If even one file is misplaced, it becomes a serious problem.
That is why SetFile is built around a custom logging system.
To fully understand and control this behavior, I implemented the logging system from scratch instead of relying on third-party logging frameworks.
What is logs ?
A log is simply a structured record of what happened in a system.
In SetFile, logs answer critical questions:
Which files were moved?
From where to where?
When did it happen?
What command triggered it?
Were there any warnings or errors?
Without logs, automatic file management would be dangerous.
With logs, it becomes safe, reversible, and trustworthy.
How I Implemented it from scratch ?
SetFile uses two separate log files , each with a distinct responsibility.
1. setfile.log — System Log
This file stores:
User commands
Program start and exit
Predictions
Warnings
Errors
It acts as the system audit trail.
2. moves.log — File Movement Ledger
This file is the backbone of the revert system.
Every time a file is moved, an entry is written in the form:
filename → source → destination
This makes it possible to reverse any operation by simply swapping destination and source.If no file is moved, no entry is created — which guarantees that only real changes are reversible.
Log Functions
SetFile uses four log categories:
| Type | Purpose |
| INFO | General system events |
| ERROR | Failures or exceptions |
| WARNING | Non-fatal issues |
| MOVES | Records of file movement |
The MOVES category is especially important because it drives the revert command.
File Processing Pipeline
Before files can be organized, they must be analyzed.
1. reader.py
This module reads supported file types and extracts text content.
Currently supported:
.xlsx.doc.pdf.csv.txt
This text is passed to the classification model.
2. file_rules.py
Not all file types can be read as text.
This module:
Checks whether a file extension is supported
Assigns a fallback label if it is not
For example:
.exe→setup.zip→archive
This prevents the AI model from being fed binary data, which would degrade accuracy.
Organize Command
The primary user command is:
setfile organize --path <folder>
If --path is not provided, SetFile defaults to the current directory using os.curdir.
Processing Flow
Once the command runs:
The target folder is scanned
Only files are selected (folders are skipped using
pathlib)Each file goes through the pipeline:
a) Extension Check
file_rules.py verifies if the extension is supported.
b) Content Reading
If supported, reader.py extracts the text.
If not supported, a label is assigned based on extension.
c) Classification
The model predicts a category for supported files.
d) Folder Assignment
A folder is created (if needed) based on the label.
e) File Move
The file is moved into its new category folder.
f) Logging
Every step is recorded in setfile.log.
Every file movement is recorded in moves.log.
Why This Design Matters
Because of this architecture:
Every action is traceable
Every move is reversible
Every error is auditable
Users stay in control
This is what allows SetFile to automate file organization without risking data loss.
What’s Next
Now that we have a reliable logging system and a working organize command, the next step is to implement:
The Revert System
In the next blog, we’ll explore how moves.log enables SetFile to undo any operation safely.
Following is the link of source code. Also contribution and suggestions are welcomed!
Github Link : https://github.com/VivekPrajapati-Git/setfile