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+
2729from prismalog .argparser import extract_logging_args , get_argument_parser
2830from 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 ("\n About 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 ("\n CRITICAL 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
0 commit comments