Skip to content

Commit 8abe2fc

Browse files
committed
fix --verbose and document it
1 parent 4404d0d commit 8abe2fc

2 files changed

Lines changed: 101 additions & 17 deletions

File tree

Readme.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,10 +236,79 @@ Configuration can be provided via a JSON file. When using the CLI, the `--server
236236
| `sleep_time` | Wait time when server is busy (seconds) | 5 |
237237
| `timeout` | Client-side timeout (seconds) | 180 |
238238
| `coordinates` | XML elements for coordinate extraction | See above |
239+
| `logging` | Logging configuration (level, format, file output) | See Logging section |
239240

240241
> [!TIP]
241242
> Since version 0.0.12, the config file is optional. The client will use default localhost settings if no configuration is provided.
242243
244+
### Logging Configuration
245+
246+
The client provides configurable logging with different verbosity levels. By default, only essential statistics and warnings are shown.
247+
248+
#### Logging Behavior
249+
250+
- **Without `--verbose`**: Shows only essential information and warnings/errors
251+
- **With `--verbose`**: Shows detailed processing information at INFO level
252+
253+
#### Always Visible Output
254+
255+
The following information is always displayed regardless of the `--verbose` flag:
256+
257+
```bash
258+
Found 1000 file(s) to process
259+
Processing completed: 950 out of 1000 files processed
260+
Errors: 50 out of 1000 files processed
261+
Processing completed in 120.5 seconds
262+
```
263+
264+
#### Verbose Output (`--verbose`)
265+
266+
When the `--verbose` flag is used, additional detailed information is displayed:
267+
268+
- Server connection status
269+
- Individual file processing details
270+
- JSON conversion messages
271+
- Detailed error messages
272+
- Processing progress information
273+
274+
#### Examples
275+
276+
```bash
277+
# Clean output - only essential statistics
278+
grobid_client --input pdfs/ processFulltextDocument
279+
# Output:
280+
# Found 1000 file(s) to process
281+
# Processing completed: 950 out of 1000 files processed
282+
# Errors: 50 out of 1000 files processed
283+
# Processing completed in 120.5 seconds
284+
285+
# Verbose output - detailed processing information
286+
grobid_client --input pdfs/ --verbose processFulltextDocument
287+
# Output includes all essential stats PLUS:
288+
# GROBID server http://localhost:8070 is up and running
289+
# JSON file example.json does not exist, generating JSON from existing TEI...
290+
# Successfully created JSON file: example.json
291+
# ... and other detailed processing information
292+
```
293+
294+
#### Configuration File Logging
295+
296+
The config file can include logging settings:
297+
298+
```json
299+
{
300+
"grobid_server": "http://localhost:8070",
301+
"logging": {
302+
"level": "WARNING",
303+
"format": "%(asctime)s - %(levelname)s - %(message)s",
304+
"console": true,
305+
"file": null
306+
}
307+
}
308+
```
309+
310+
**Note**: The `--verbose` command line flag always takes precedence over configuration file logging settings.
311+
243312
## 🔬 Services
244313

245314
### Fulltext Document Processing

grobid_client/grobid_client.py

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class GrobidClient(ApiClient):
6060
"note"
6161
],
6262
'logging': {
63-
'level': 'INFO',
63+
'level': 'WARNING',
6464
'format': '%(asctime)s - %(levelname)s - %(message)s',
6565
'console': True,
6666
'file': None, # Disabled by default
@@ -77,15 +77,19 @@ def __init__(
7777
sleep_time=None,
7878
timeout=None,
7979
config_path=None,
80-
check_server=True
80+
check_server=True,
81+
verbose=False
8182
):
83+
# Store verbose parameter for logging configuration
84+
self.verbose = verbose
85+
8286
# Initialize config with defaults
8387
self.config = copy.deepcopy(self.DEFAULT_CONFIG)
84-
88+
8589
# Load config file (which may override current values)
8690
if config_path:
8791
self._load_config(config_path)
88-
92+
8993
# Constructor parameters take precedence over config file values
9094
# This ensures CLI arguments override config file values
9195
self._set_config_params({
@@ -96,7 +100,7 @@ def __init__(
96100
'timeout': timeout
97101
})
98102

99-
# Configure logging based on config
103+
# Configure logging based on config and verbose flag
100104
self._configure_logging()
101105

102106
if check_server:
@@ -129,9 +133,20 @@ def _configure_logging(self):
129133
# Get logging config with defaults
130134
log_config = self.config.get('logging', {})
131135

132-
# Parse log level
133-
log_level_str = log_config.get('level', 'INFO').upper()
134-
log_level = getattr(logging, log_level_str, logging.INFO)
136+
# Parse log level - verbose flag takes precedence over config
137+
if self.verbose:
138+
# When verbose is explicitly set via command line, always use INFO level
139+
log_level_str = 'INFO'
140+
log_level = logging.INFO
141+
else:
142+
# Use config file level when not verbose, but default to WARNING
143+
config_level_str = log_config.get('level', 'WARNING').upper()
144+
# If config specifies INFO but verbose is False, use WARNING instead
145+
if config_level_str == 'INFO':
146+
log_level_str = 'WARNING'
147+
else:
148+
log_level_str = config_level_str
149+
log_level = getattr(logging, log_level_str, logging.WARNING)
135150

136151
# Parse log format
137152
log_format = log_config.get('format', '%(asctime)s - %(levelname)s - %(message)s')
@@ -346,7 +361,7 @@ def process(
346361
self.logger.warning(f"No eligible files found in {input_path}")
347362
return
348363

349-
self.logger.info(f"Found {total_files} file(s) to process")
364+
print(f"Found {total_files} file(s) to process")
350365

351366
# Counter for actually processed files
352367
processed_files_count = 0
@@ -412,9 +427,9 @@ def process(
412427
processed_files_count += batch_processed
413428
errors_files_count += batch_errors
414429

415-
# Log final statistics
416-
self.logger.info(f"Processing completed: {processed_files_count} out of {total_files} files processed")
417-
self.logger.info(f"Errors: {errors_files_count} out of {total_files} files processed")
430+
# Log final statistics - always visible
431+
print(f"Processing completed: {processed_files_count} out of {total_files} files processed")
432+
print(f"Errors: {errors_files_count} out of {total_files} files processed")
418433

419434
def process_batch(
420435
self,
@@ -793,7 +808,7 @@ def main():
793808
parser.add_argument(
794809
"--verbose",
795810
action="store_true",
796-
help="print information about processed files in the console",
811+
help="enable detailed logging (INFO level) - shows file-by-file processing details, server status, and JSON conversion messages. Without this flag, only essential statistics and warnings/errors are shown.",
797812
)
798813

799814
parser.add_argument(
@@ -828,13 +843,13 @@ def main():
828843
except ValueError:
829844
temp_logger.warning(f"Invalid concurrency parameter n: {args.n}. Using default value n = 10")
830845

831-
# Initialize GrobidClient which will configure logging based on config.json
846+
# Initialize GrobidClient which will configure logging based on config.json and verbose flag
832847
try:
833848
# Only pass grobid_server if it was explicitly provided (not the default)
834-
client_kwargs = {'config_path': config_path}
849+
client_kwargs = {'config_path': config_path, 'verbose': args.verbose}
835850
if args.server is not None: # Only override if user specified a different server
836851
client_kwargs['grobid_server'] = args.server
837-
852+
838853
client = GrobidClient(**client_kwargs)
839854
# Now use the client's logger for all subsequent logging
840855
logger = client.logger
@@ -895,7 +910,7 @@ def main():
895910
exit(1)
896911

897912
runtime = round(time.time() - start_time, 3)
898-
logger.info(f"Processing completed in {runtime} seconds")
913+
print(f"Processing completed in {runtime} seconds")
899914

900915

901916
if __name__ == "__main__":

0 commit comments

Comments
 (0)