2929from .prometheus import PrometheusServer
3030from .rc2udp import RC2UDPServer
3131
32+ logger = structlog .get_logger ()
33+
3234
3335def parse_args (argv : Sequence [str ] | None ) -> argparse .Namespace :
3436 """Parse and return the parsed command line arguments."""
@@ -83,7 +85,6 @@ def configure_logging(log_format: str = "plain") -> None:
8385
8486async def start_servers (config : configparser .ConfigParser ) -> None :
8587 """Start all servers in asyncio tasks or threads and then busy-loop."""
86- log = structlog .get_logger ("ircstream.main" )
8788 loop = asyncio .get_running_loop ()
8889
8990 try :
@@ -92,14 +93,14 @@ async def start_servers(config: configparser.ConfigParser) -> None:
9293 irc_coro = ircserver .serve ()
9394 irc_task = asyncio .create_task (irc_coro )
9495 else :
95- log .critical ('Invalid configuration, missing section "irc"' )
96+ logger .critical ('Invalid configuration, missing section "irc"' )
9697 raise SystemExit (- 1 )
9798
9899 if "rc2udp" in config :
99100 rc2udp_coro = RC2UDPServer (config ["rc2udp" ], ircserver ).serve ()
100101 rc2udp_task = asyncio .create_task (rc2udp_coro ) # noqa: F841 pylint: disable=unused-variable
101102 else :
102- log .warning ("RC2UDP is not enabled in the config; server usefulness may be limited" )
103+ logger .warning ("RC2UDP is not enabled in the config; server usefulness may be limited" )
103104
104105 if "prometheus" in config :
105106 prom_server = PrometheusServer (config ["prometheus" ], ircserver .metrics_registry )
@@ -108,7 +109,7 @@ async def start_servers(config: configparser.ConfigParser) -> None:
108109
109110 await asyncio .wait_for (irc_task , timeout = None ) # run forever
110111 except OSError as exc :
111- log .critical (f"System error: { exc .strerror } " , errno = errno .errorcode [exc .errno ])
112+ logger .critical (f"System error: { exc .strerror } " , errno = errno .errorcode [exc .errno ])
112113 raise SystemExit (- 2 ) from exc
113114
114115
@@ -119,19 +120,18 @@ def run(argv: Sequence[str] | None = None) -> None:
119120 configure_logging (options .log_format )
120121 # only set e.g. INFO or DEBUG for our own loggers
121122 structlog .get_logger ("ircstream" ).setLevel (options .log_level )
122- log = structlog .get_logger ("ircstream.main" )
123- log .info ("Starting IRCStream" , config_file = str (options .config_file ), version = __version__ )
123+ logger .info ("Starting IRCStream" , config_file = str (options .config_file ), version = __version__ )
124124
125125 config = configparser .ConfigParser (strict = True )
126126 try :
127127 with options .config_file .open (encoding = "utf-8" ) as config_fh :
128128 config .read_file (config_fh )
129129 except OSError as exc :
130- log .critical (f"Cannot open configuration file: { exc .strerror } " , errno = errno .errorcode [exc .errno ])
130+ logger .critical (f"Cannot open configuration file: { exc .strerror } " , errno = errno .errorcode [exc .errno ])
131131 raise SystemExit (- 1 ) from exc
132132 except configparser .Error as exc :
133133 msg = repr (exc ).replace ("\n " , " " ) # configparser exceptions sometimes include newlines
134- log .critical (f"Invalid configuration, { msg } " )
134+ logger .critical (f"Invalid configuration, { msg } " )
135135 raise SystemExit (- 1 ) from exc
136136
137137 try :
0 commit comments