Skip to content

Commit

Permalink
Reduce AppInsights verbosity (#202)
Browse files Browse the repository at this point in the history
  • Loading branch information
c-w authored May 28, 2019
1 parent 1bb2d57 commit 5541642
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
1 change: 1 addition & 0 deletions opwen_email_server/integration/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def build_app(apis, host=_host, port=_port, ui=_ui):

app.app.config['APPINSIGHTS_INSTRUMENTATIONKEY'] = config.APPINSIGHTS_KEY
app.app.config['APPINSIGHTS_ENDPOINT_URI'] = config.APPINSIGHTS_HOST
app.app.config['APPINSIGHTS_DISABLE_TRACE_LOGGING'] = True
AppInsights(app.app)

return app
Expand Down
11 changes: 3 additions & 8 deletions opwen_email_server/utils/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from logging import Handler
from logging import Logger
from logging import StreamHandler
from logging import getLevelName
from logging import getLogger
from typing import Any
from typing import Iterable
Expand All @@ -16,7 +17,6 @@
from applicationinsights.channel import AsynchronousSender
from applicationinsights.channel import NullSender
from applicationinsights.channel import TelemetryChannel
from applicationinsights.logging import LoggingHandler
from cached_property import cached_property

from opwen_email_server.config import APPINSIGHTS_HOST
Expand Down Expand Up @@ -51,10 +51,6 @@ def _default_log_handlers(self) -> Iterable[Handler]:
stderr.setFormatter(Formatter(STDERR))
handlers.append(stderr)

handlers.append(LoggingHandler(
self._telemetry_key,
telemetry_channel=self._telemetry_channel))

return handlers

@cached_property
Expand Down Expand Up @@ -98,9 +94,8 @@ def _log(self, level: int, log_message: str, log_args: Iterable[Any]):
args.extend(log_args)
message = SEPARATOR.join(message_parts)
self._logger.log(level, message, *args)
self._telemetry_client.track_trace(message % tuple(args), severity=getLevelName(level))

def log_event(self, event_name: str, properties: Optional[dict] = None):
self.log_info('%s%s%s', event_name, SEPARATOR, properties)

self._logger.info('%s%s%s', event_name, SEPARATOR, properties)
self._telemetry_client.track_event(event_name, properties)
self._telemetry_channel.flush()

0 comments on commit 5541642

Please sign in to comment.