Skip to content

Commit 0c48ab3

Browse files
committed
prerelease changes in package
1 parent c197507 commit 0c48ab3

18 files changed

+84
-57
lines changed

docs/source/installation.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ Configure logging using command-line arguments:
7777
# Use configuration file
7878
python your_script.py --log-config config.yaml
7979
80-
# Disable exit on critical errors
81-
python your_script.py --no-exit-on-critical
80+
# Activate exit on critical errors
81+
python your_script.py --exit-on-critical
8282
8383
# Disable colored output
8484
python your_script.py --no-color
@@ -97,8 +97,8 @@ Available Arguments
9797
--log-config FILE
9898
Use YAML configuration file
9999

100-
--no-exit-on-critical
101-
Prevent program termination on critical errors
100+
--exit-on-critical
101+
Terminate program on critical errors
102102

103103
--no-color
104104
Disable colored console output

docs/source/usage.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ Common Arguments
5050
--log-config FILE
5151
Use a YAML configuration file for logging settings
5252

53-
--no-exit-on-critical
54-
Prevent program termination on critical errors
53+
--exit-on-critical
54+
Terminate program on critical errors
5555

5656
--no-color
5757
Disable colored console output
@@ -84,7 +84,7 @@ YAML Configuration:
8484
log_dir: logs
8585
rotation_size_mb: 10
8686
backup_count: 5
87-
exit_on_critical: true
87+
exit_on_critical: false
8888
8989
# Control third-party libraries
9090
external_loggers:

example/config_showcase.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
# Custom log format:
2626
python config_showcase.py --log-format "%(asctime)s [%(levelname)s] %(message)s"
2727
28-
# Disable exit on critical:
29-
python config_showcase.py --no-exit-on-critical
28+
# Activate exit on critical:
29+
python config_showcase.py --exit-on-critical
3030
3131
# Customize log directory:
3232
python config_showcase.py --log-dir ./my_logs
@@ -36,10 +36,11 @@
3636
from time import sleep
3737

3838
from prismalog import LoggingConfig, get_logger
39-
from prismalog.argparser import get_argument_parser, extract_logging_args
39+
from prismalog.argparser import extract_logging_args, get_argument_parser
4040

4141

42-
def main():
42+
def main() -> None:
43+
"""Main function to demonstrate prismalog configuration keys."""
4344
# Get the standard argument parser
4445
parser = get_argument_parser(description="prismalog Configuration Showcase")
4546

@@ -103,7 +104,7 @@ def main():
103104
exit_on_critical = LoggingConfig.get("exit_on_critical")
104105
log.info(f"8. exit_on_critical = {exit_on_critical}")
105106
log.info(f" Whether to terminate the program on critical logs")
106-
log.info(f" Set with: --no-exit-on-critical to disable")
107+
log.info(f" Set with: --exit-on-critical to activate")
107108

108109
# 9. test_mode - For testing the logger itself
109110
test_mode = LoggingConfig.get("test_mode")
@@ -124,14 +125,15 @@ def main():
124125
# Demonstrate exit_on_critical
125126
if exit_on_critical:
126127
log.info("\nAbout to log a CRITICAL message, which will terminate the program")
127-
log.info("To prevent termination, run with: --no-exit-on-critical")
128-
sleep(1) # Give user time to read
128+
log.info("This happens because you used: --exit-on-critical")
129+
sleep(1)
129130
log.critical("This is a CRITICAL message - program will exit now")
130131
else:
131-
log.info("\nCRITICAL messages won't terminate the program (--no-exit-on-critical was used)")
132+
log.info("\nCRITICAL messages won't terminate the program (default behavior)")
132133
log.critical("This is a CRITICAL message - program continues")
133134
log.info("Program completed successfully")
135+
log.info("To change this behavior, use --exit-on-critical")
134136

135137

136138
if __name__ == "__main__":
137-
main()
139+
main()

example/example_script.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@
2020
# Run with custom configuration:
2121
python example_script.py --log-config path/to/config.yaml
2222
23-
# Run with critical messages allowed (no exit):
24-
python example_script.py --no-exit-on-critical
23+
# Run with critical messages allowed to exit:
24+
python example_script.py --exit-on-critical
2525
"""
2626

27+
from time import sleep
28+
2729
from prismalog.argparser import extract_logging_args, get_argument_parser
2830
from prismalog.log import LoggingConfig, get_logger
2931

@@ -47,10 +49,12 @@ def main() -> None:
4749

4850
# Create logger
4951
logger = get_logger("example")
52+
exit_on_critical = logging_args.get("exit_on_critical", True)
53+
log_level = logging_args.get("default_level", "INFO")
5054

5155
# Example usage - show current settings
52-
logger.info(f"Current log level: {logging_args.get('default_level', 'INFO')}")
53-
logger.info(f"Exit on critical: {not logging_args.get('exit_on_critical', True)}")
56+
logger.info("Current log level: %s", log_level)
57+
logger.info("Exit on critical: %s", exit_on_critical)
5458

5559
# Demonstrate different log levels
5660
logger.debug("This is a debug message")
@@ -59,13 +63,18 @@ def main() -> None:
5963
logger.error("This is an error message")
6064

6165
# Warn user about potential program termination
62-
if logging_args.get("exit_on_critical", True):
63-
logger.warning("About to log a CRITICAL message which will terminate the program")
64-
logger.warning("(Use --no-exit-on-critical to prevent termination)")
66+
if exit_on_critical:
67+
logger.info("\nAbout to log a CRITICAL message, which will terminate the program")
68+
logger.info("This happens because you used: --exit-on-critical")
69+
sleep(1)
70+
logger.critical("This is a CRITICAL message - program will exit now")
6571
else:
66-
logger.info("Program will continue after critical message")
72+
logger.info("\nCRITICAL messages won't terminate the program (default behavior)")
73+
logger.critical("This is a CRITICAL message - program continues")
74+
logger.info("Program completed successfully")
75+
logger.info("To change this behavior, use --exit-on-critical")
6776

68-
# This will terminate the program if exit_on_critical is true
77+
# This will not terminate the program since exit_on_critical is false
6978
logger.critical("This is a critical message")
7079

7180
# These will only be reached if exit_on_critical is false

example/integrations/nltk_example/nltk_example.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,20 @@
2424
python nltk_example.py --log-level DEBUG
2525
"""
2626

27+
from typing import TYPE_CHECKING, Union
28+
29+
if TYPE_CHECKING:
30+
from logging import Logger
31+
from prismalog.log import ColoredLogger
32+
2733
import nltk # type: ignore
2834
from nltk.tokenize import word_tokenize # type: ignore
2935

30-
from prismalog.log import LoggingConfig, get_logger
3136
from prismalog.argparser import extract_logging_args, get_argument_parser
37+
from prismalog.log import LoggingConfig, get_logger
3238

3339

34-
def download_nltk_data(logger) -> bool:
40+
def download_nltk_data(logger: Union["Logger", "ColoredLogger"]) -> bool:
3541
"""
3642
Download NLTK data with logging configuration from config file or CLI args.
3743
@@ -41,7 +47,7 @@ def download_nltk_data(logger) -> bool:
4147
# Log configuration info
4248
config_file = LoggingConfig.get("config_file", None)
4349
if config_file:
44-
logger.info(f"Using configuration from: {config_file}")
50+
logger.info("Using configuration from: %s", config_file)
4551
else:
4652
logger.info("Using default configuration")
4753

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
nltk>=3.9.1
1+
nltk>=3.9.1

prismalog/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from typing import Optional
77

88
from .config import LoggingConfig
9-
from .log import ColoredLogger, ColoredFormatter, MultiProcessingLog, CriticalExitHandler, get_logger
9+
from .log import ColoredFormatter, ColoredLogger, CriticalExitHandler, MultiProcessingLog, get_logger
1010

1111

1212
def setup_logging(config_file: Optional[str] = None, use_cli_args: bool = True) -> dict:

prismalog/argparser.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
--log-format Format string for log messages
2323
--no-color Disable colored console output
2424
--disable-rotation Disable log file rotation
25-
--no-exit-on-critical Don't exit program on critical errors
25+
--exit-on-critical Exit program on critical errors
2626
--rotation-size Log file rotation size in MB
2727
--backup-count Number of backup log files to keep
2828
@@ -64,7 +64,7 @@
6464
"""
6565

6666
import argparse
67-
from typing import Dict, Any, Optional
67+
from typing import Any, Dict, Optional
6868

6969

7070
class LoggingArgumentParser:
@@ -113,10 +113,10 @@ def add_arguments(parser: Optional[argparse.ArgumentParser] = None) -> argparse.
113113
)
114114

115115
parser.add_argument(
116-
"--no-exit-on-critical",
116+
"--exit-on-critical",
117117
dest="exit_on_critical",
118-
action="store_false",
119-
help="Don't exit program on critical errors",
118+
action="store_true",
119+
help="Exit the program on critical errors",
120120
)
121121

122122
# Numeric options

prismalog/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ class LoggingConfig:
107107
"log_format": "%(asctime)s - %(filename)s - %(name)s - [%(levelname)s] - %(message)s",
108108
"colored_console": True,
109109
"disable_rotation": False,
110-
"exit_on_critical": True, # Whether to exit the program on critical logs
110+
"exit_on_critical": False, # Whether to exit the program on critical logs
111111
"test_mode": False, # Whether the logger is running in test mode
112112
}
113113

prismalog/log.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,7 @@ def critical(self, msg: str, *args: Any, **kwargs: Any) -> None:
683683
"""
684684
Logs a critical message.
685685
686-
Note: If exit_on_critical=True in config (default), this will terminate the program.
686+
Note: If exit_on_critical=True in config, this will terminate the program.
687687
688688
Args:
689689
msg: The message to log

0 commit comments

Comments
 (0)