Skip to content

Commit c579705

Browse files
authored
Flush logs on signal interrupt (#847)
# Description What - Flush logs on signal interrupt Why - Logs that left in the buffer are not being send when application exits ## Type of change - [X] Bug fix (non-breaking change which fixes an issue)
1 parent 6726ff4 commit c579705

File tree

5 files changed

+18
-5
lines changed

5 files changed

+18
-5
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
77

88
<!-- towncrier release notes start -->
99

10+
## 0.9.6 (2024-07-30)
11+
12+
### Bug Fixes
13+
14+
- Flush all remaining buffered logs when exiting application
15+
16+
1017
## 0.9.5 (2024-07-23)
1118

1219
### Bug Fixes

port_ocean/log/logger_setup.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from port_ocean.config.settings import LogLevelType
1010
from port_ocean.log.handlers import HTTPMemoryHandler
1111
from port_ocean.log.sensetive import sensitive_log_filter
12+
from port_ocean.utils.signal import signal_handler
1213

1314

1415
def setup_logger(level: LogLevelType, enable_http_handler: bool) -> None:
@@ -53,7 +54,10 @@ def _http_loguru_handler(level: LogLevelType) -> None:
5354
)
5455
logger.configure(patcher=exception_deserializer)
5556

56-
queue_listener = QueueListener(queue, HTTPMemoryHandler())
57+
http_memory_handler = HTTPMemoryHandler()
58+
signal_handler.register(http_memory_handler.flush)
59+
60+
queue_listener = QueueListener(queue, http_memory_handler)
5761
queue_listener.start()
5862

5963

port_ocean/ocean.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from port_ocean.log.sensetive import sensitive_log_filter
2323
from port_ocean.middlewares import request_handler
2424
from port_ocean.utils.repeat import repeat_every
25-
from port_ocean.utils.signal import signal_handler, init_signal_handler
25+
from port_ocean.utils.signal import signal_handler
2626
from port_ocean.version import __integration_version__
2727

2828

@@ -97,14 +97,14 @@ async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
9797
@asynccontextmanager
9898
async def lifecycle(_: FastAPI) -> AsyncIterator[None]:
9999
try:
100-
init_signal_handler()
101100
await self.integration.start()
102101
await self._setup_scheduled_resync()
103102
yield None
104-
signal_handler.exit()
105103
except Exception:
106104
logger.exception("Integration had a fatal error. Shutting down.")
107105
sys.exit("Server stopped")
106+
finally:
107+
signal_handler.exit()
108108

109109
self.fast_api_app.router.lifespan_context = lifecycle
110110
await self.fast_api_app(scope, receive, send)

port_ocean/run.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from port_ocean.log.logger_setup import setup_logger
1414
from port_ocean.ocean import Ocean
1515
from port_ocean.utils.misc import get_spec_file, load_module
16+
from port_ocean.utils.signal import init_signal_handler
1617

1718

1819
def _get_default_config_factory() -> None | Type[BaseModel]:
@@ -33,6 +34,7 @@ def run(
3334
) -> None:
3435
application_settings = ApplicationSettings(log_level=log_level, port=port)
3536

37+
init_signal_handler()
3638
setup_logger(
3739
application_settings.log_level,
3840
enable_http_handler=application_settings.enable_http_logging,

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "port-ocean"
3-
version = "0.9.5"
3+
version = "0.9.6"
44
description = "Port Ocean is a CLI tool for managing your Port projects."
55
readme = "README.md"
66
homepage = "https://app.getport.io"

0 commit comments

Comments
 (0)