29
29
from .prometheus import PrometheusServer
30
30
from .rc2udp import RC2UDPServer
31
31
32
+ logger = structlog .get_logger ()
33
+
32
34
33
35
def parse_args (argv : Sequence [str ] | None ) -> argparse .Namespace :
34
36
"""Parse and return the parsed command line arguments."""
@@ -83,7 +85,6 @@ def configure_logging(log_format: str = "plain") -> None:
83
85
84
86
async def start_servers (config : configparser .ConfigParser ) -> None :
85
87
"""Start all servers in asyncio tasks or threads and then busy-loop."""
86
- log = structlog .get_logger ("ircstream.main" )
87
88
loop = asyncio .get_running_loop ()
88
89
89
90
try :
@@ -92,14 +93,14 @@ async def start_servers(config: configparser.ConfigParser) -> None:
92
93
irc_coro = ircserver .serve ()
93
94
irc_task = asyncio .create_task (irc_coro )
94
95
else :
95
- log .critical ('Invalid configuration, missing section "irc"' )
96
+ logger .critical ('Invalid configuration, missing section "irc"' )
96
97
raise SystemExit (- 1 )
97
98
98
99
if "rc2udp" in config :
99
100
rc2udp_coro = RC2UDPServer (config ["rc2udp" ], ircserver ).serve ()
100
101
rc2udp_task = asyncio .create_task (rc2udp_coro ) # noqa: F841 pylint: disable=unused-variable
101
102
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" )
103
104
104
105
if "prometheus" in config :
105
106
prom_server = PrometheusServer (config ["prometheus" ], ircserver .metrics_registry )
@@ -108,7 +109,7 @@ async def start_servers(config: configparser.ConfigParser) -> None:
108
109
109
110
await asyncio .wait_for (irc_task , timeout = None ) # run forever
110
111
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 ])
112
113
raise SystemExit (- 2 ) from exc
113
114
114
115
@@ -119,19 +120,18 @@ def run(argv: Sequence[str] | None = None) -> None:
119
120
configure_logging (options .log_format )
120
121
# only set e.g. INFO or DEBUG for our own loggers
121
122
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__ )
124
124
125
125
config = configparser .ConfigParser (strict = True )
126
126
try :
127
127
with options .config_file .open (encoding = "utf-8" ) as config_fh :
128
128
config .read_file (config_fh )
129
129
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 ])
131
131
raise SystemExit (- 1 ) from exc
132
132
except configparser .Error as exc :
133
133
msg = repr (exc ).replace ("\n " , " " ) # configparser exceptions sometimes include newlines
134
- log .critical (f"Invalid configuration, { msg } " )
134
+ logger .critical (f"Invalid configuration, { msg } " )
135
135
raise SystemExit (- 1 ) from exc
136
136
137
137
try :
0 commit comments