Skip to content

Commit b412491

Browse files
committed
Setup graylog logging outside of Zocalo configuration
This should remove the need for the ZOCALO_CONFIG environment variable to be set when starting a Murfey server
1 parent 371ac4d commit b412491

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

src/murfey/server/__init__.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
from threading import Thread
1414
from typing import Any, Dict, List, NamedTuple, Tuple
1515

16+
import graypy
1617
import mrcfile
1718
import numpy as np
1819
import uvicorn
1920
import workflows
20-
import zocalo.configuration
2121
from backports.entry_points_selectable import entry_points
2222
from fastapi import Request
2323
from fastapi.templating import Jinja2Templates
@@ -273,18 +273,18 @@ def run():
273273
default=0,
274274
)
275275

276+
security_config = get_security_config()
276277
# setup logging
277-
zc = zocalo.configuration.from_file()
278-
zc.activate()
278+
if security_config.graylog_host:
279+
handler = graypy.GELFUDPHandler(
280+
security_config.graylog_host, security_config.graylog_port, level_names=True
281+
)
282+
root_logger = logging.getLogger()
283+
root_logger.addHandler(handler)
279284

280285
# Install a log filter to all existing handlers.
281-
# At this stage this will exclude console loggers, but will cover
282-
# any Graylog logging set up by the environment activation
283286
LogFilter.install()
284287

285-
zc.add_command_line_options(parser)
286-
287-
security_config = get_security_config()
288288
workflows.transport.load_configuration_file(security_config.rabbitmq_credentials)
289289

290290
args = parser.parse_args()

src/murfey/util/config.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import yaml
1010
from backports.entry_points_selectable import entry_points
11-
from pydantic import BaseModel, BaseSettings, Extra
11+
from pydantic import BaseModel, BaseSettings, Extra, validator
1212

1313

1414
class MachineConfig(BaseModel, extra=Extra.allow): # type: ignore
@@ -94,6 +94,16 @@ class Security(BaseModel):
9494
auth_type: Literal["password", "cookie"] = "password"
9595
cookie_key: str = ""
9696
feedback_queue: str = "murfey_feedback"
97+
graylog_host: str = ""
98+
graylog_port: Optional[int] = None
99+
100+
@validator("graylog_port")
101+
def check_port_present_if_host_is(
102+
cls, v: Optional[int], values: dict, **kwargs
103+
) -> Optional[int]:
104+
if values["graylog_host"] and v is None:
105+
raise ValueError("The Graylog port must be set if the Graylog host is")
106+
return v
97107

98108

99109
def security_from_file(config_file_path: Path) -> Security:

0 commit comments

Comments
 (0)