import logging

import sanic

import raven
import raven_aiohttp
from raven.handlers.logging import SentryHandler


class SanicSentry:
    def __init__(self, app=None):
        self.app = None
        self.handler = None
        self.client = None
        if app is not None:
            self.init_app(app)

    def init_app(self, app: sanic.Sanic):
        self.client = raven.Client(
            dsn=app.config['SENTRY_DSN'],
            transport=raven_aiohttp.AioHttpTransport,
        )
        self.handler = SentryHandler(client=self.client, level=app.config.get('SENTRY_LEVEL', logging.ERROR))
        logger = logging.getLogger('sanic')
        logger.addHandler(self.handler)
        self.app = app
        self.app.sentry = self

import logging

import sanic
from sanic.log import logger

import raven
import raven_aiohttp
from raven.handlers.logging import SentryHandler


class SanicSentry:
    def __init__(self, app=None):
        self.app = None
        self.handler = None
        self.client = None
        if app is not None:
            self.init_app(app)

    def init_app(self, app: sanic.Sanic):
        self.client = raven.Client(
            dsn=app.config['SENTRY_DSN'],
            transport=raven_aiohttp.AioHttpTransport,
        )
        self.handler = SentryHandler(client=self.client, level=app.config.get('SENTRY_LEVEL', logging.ERROR))
        logger.addHandler(self.handler)
        self.app = app
        self.app.sentry = self

Fix to work on Sanic 0.7
Fix to work on Sanic 0.7

Sanic 0.7 changed the logger name and is now using the 'root' logger (instead of 'sanic').
I think it is better to import it directly from Sanic than to use `logging.getLogger` to avoid this kind of problem in the future...
  import logging
  
  import sanic
+ from sanic.log import logger
  
  import raven
  import raven_aiohttp
  from raven.handlers.logging import SentryHandler
  
  
  class SanicSentry:
      def __init__(self, app=None):
          self.app = None
          self.handler = None
          self.client = None
          if app is not None:
              self.init_app(app)
  
      def init_app(self, app: sanic.Sanic):
          self.client = raven.Client(
              dsn=app.config['SENTRY_DSN'],
              transport=raven_aiohttp.AioHttpTransport,
          )
          self.handler = SentryHandler(client=self.client, level=app.config.get('SENTRY_LEVEL', logging.ERROR))
-         logger = logging.getLogger('sanic')
          logger.addHandler(self.handler)
          self.app = app
          self.app.sentry = self
  
Fix to work on Sanic 0.7
## Code Before:
import logging

import sanic

import raven
import raven_aiohttp
from raven.handlers.logging import SentryHandler


class SanicSentry:
    def __init__(self, app=None):
        self.app = None
        self.handler = None
        self.client = None
        if app is not None:
            self.init_app(app)

    def init_app(self, app: sanic.Sanic):
        self.client = raven.Client(
            dsn=app.config['SENTRY_DSN'],
            transport=raven_aiohttp.AioHttpTransport,
        )
        self.handler = SentryHandler(client=self.client, level=app.config.get('SENTRY_LEVEL', logging.ERROR))
        logger = logging.getLogger('sanic')
        logger.addHandler(self.handler)
        self.app = app
        self.app.sentry = self

## Instruction:
Fix to work on Sanic 0.7
## Code After:
import logging

import sanic
from sanic.log import logger

import raven
import raven_aiohttp
from raven.handlers.logging import SentryHandler


class SanicSentry:
    def __init__(self, app=None):
        self.app = None
        self.handler = None
        self.client = None
        if app is not None:
            self.init_app(app)

    def init_app(self, app: sanic.Sanic):
        self.client = raven.Client(
            dsn=app.config['SENTRY_DSN'],
            transport=raven_aiohttp.AioHttpTransport,
        )
        self.handler = SentryHandler(client=self.client, level=app.config.get('SENTRY_LEVEL', logging.ERROR))
        logger.addHandler(self.handler)
        self.app = app
        self.app.sentry = self
