Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

consolidate logger logic to shared #818

Merged
merged 4 commits into from
Sep 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 0 additions & 19 deletions stream_alert/alert_merger/__init__.py
Original file line number Diff line number Diff line change
@@ -1,19 +0,0 @@
"""Initialize logging for the alert merger."""
import logging
import os

# Create a package level logger to import
LEVEL = os.environ.get('LOGGER_LEVEL', 'INFO').upper()

# Cast integer levels to avoid a ValueError
if LEVEL.isdigit():
LEVEL = int(LEVEL)

logging.basicConfig(format='%(name)s [%(levelname)s]: [%(module)s.%(funcName)s] %(message)s')

LOGGER = logging.getLogger('StreamAlert')
try:
LOGGER.setLevel(LEVEL)
except (TypeError, ValueError) as err:
LOGGER.setLevel('INFO')
LOGGER.error('Defaulting to INFO logging: %s', err)
7 changes: 5 additions & 2 deletions stream_alert/alert_merger/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@
import json
import os

from stream_alert.alert_merger import LOGGER
import boto3

from stream_alert.shared.alert import Alert, AlertCreationError
from stream_alert.shared.alert_table import AlertTable
from stream_alert.shared.logger import get_logger
from stream_alert.shared.metrics import ALERT_MERGER_NAME, MetricLogger

import boto3

LOGGER = get_logger(__name__)


class AlertMergeGroup(object):
Expand Down
21 changes: 0 additions & 21 deletions stream_alert/alert_processor/__init__.py
Original file line number Diff line number Diff line change
@@ -1,21 +0,0 @@
"""Initialize logging for the alert processor."""
import logging
import os

from stream_alert.shared import ALERT_PROCESSOR_NAME as FUNCTION_NAME

# Create a package level logger to import
LEVEL = os.environ.get('LOGGER_LEVEL', 'INFO').upper()

# Cast integer levels to avoid a ValueError
if LEVEL.isdigit():
LEVEL = int(LEVEL)

logging.basicConfig(format='%(name)s [%(levelname)s]: [%(module)s.%(funcName)s] %(message)s')

LOGGER = logging.getLogger('StreamAlertOutput')
try:
LOGGER.setLevel(LEVEL)
except (TypeError, ValueError) as err:
LOGGER.setLevel('INFO')
LOGGER.error('Defaulting to INFO logging: %s', err)
5 changes: 4 additions & 1 deletion stream_alert/alert_processor/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,20 @@
from __future__ import absolute_import # Suppresses RuntimeWarning import error in Lambda
import os

from stream_alert.alert_processor import LOGGER
from stream_alert.alert_processor.outputs.output_base import StreamAlertOutput
from stream_alert.shared import backoff_handlers, NORMALIZATION_KEY, resources
from stream_alert.shared.alert import Alert, AlertCreationError
from stream_alert.shared.alert_table import AlertTable
from stream_alert.shared.config import load_config
from stream_alert.shared.logger import get_logger

import backoff
from botocore.exceptions import ClientError


LOGGER = get_logger(__name__)


class AlertProcessor(object):
"""Orchestrates delivery of alerts to the appropriate dispatchers."""
ALERT_PROCESSOR = None # AlertProcessor instance which can be re-used across Lambda invocations
Expand Down
5 changes: 4 additions & 1 deletion stream_alert/alert_processor/outputs/aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
from botocore.exceptions import ClientError
import boto3

from stream_alert.alert_processor import LOGGER
from stream_alert.alert_processor.helpers import elide_string_middle
from stream_alert.alert_processor.outputs.output_base import (
OutputDispatcher,
Expand All @@ -35,6 +34,10 @@
success_handler,
giveup_handler
)
from stream_alert.shared.logger import get_logger


LOGGER = get_logger(__name__)


class AWSOutput(OutputDispatcher):
Expand Down
5 changes: 4 additions & 1 deletion stream_alert/alert_processor/outputs/carbonblack.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@

from cbapi.response import BannedHash, Binary, CbResponseAPI

from stream_alert.alert_processor import LOGGER
from stream_alert.alert_processor.outputs.output_base import (
OutputDispatcher,
OutputProperty,
StreamAlertOutput
)
from stream_alert.shared.logger import get_logger


LOGGER = get_logger(__name__)


@StreamAlertOutput
Expand Down
5 changes: 4 additions & 1 deletion stream_alert/alert_processor/outputs/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@
import base64
import json

from stream_alert.alert_processor import LOGGER
from stream_alert.alert_processor.outputs.output_base import (
OutputDispatcher,
OutputProperty,
OutputRequestFailure,
StreamAlertOutput
)
from stream_alert.shared.logger import get_logger


LOGGER = get_logger(__name__)


@StreamAlertOutput
Expand Down
5 changes: 4 additions & 1 deletion stream_alert/alert_processor/outputs/jira.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@
import json
import os

from stream_alert.alert_processor import LOGGER
from stream_alert.alert_processor.outputs.output_base import (
OutputDispatcher,
OutputProperty,
OutputRequestFailure,
StreamAlertOutput
)
from stream_alert.shared.logger import get_logger


LOGGER = get_logger(__name__)


@StreamAlertOutput
Expand Down
5 changes: 4 additions & 1 deletion stream_alert/alert_processor/outputs/komand.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@
"""
from collections import OrderedDict

from stream_alert.alert_processor import LOGGER
from stream_alert.alert_processor.outputs.output_base import (
OutputDispatcher,
OutputProperty,
StreamAlertOutput
)
from stream_alert.shared.logger import get_logger


LOGGER = get_logger(__name__)


@StreamAlertOutput
Expand Down
6 changes: 5 additions & 1 deletion stream_alert/alert_processor/outputs/output_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,16 @@
import boto3
from botocore.exceptions import ClientError

from stream_alert.alert_processor import LOGGER
from stream_alert.shared.backoff_handlers import (
backoff_handler,
success_handler,
giveup_handler
)
from stream_alert.shared.logger import get_logger


LOGGER = get_logger(__name__)


urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
OutputProperty = namedtuple('OutputProperty',
Expand Down
5 changes: 4 additions & 1 deletion stream_alert/alert_processor/outputs/pagerduty.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import os
import backoff

from stream_alert.alert_processor import LOGGER
from stream_alert.alert_processor.outputs.output_base import (
OutputDispatcher,
OutputProperty,
Expand All @@ -29,6 +28,10 @@
success_handler,
giveup_handler
)
from stream_alert.shared.logger import get_logger


LOGGER = get_logger(__name__)


def events_v2_data(alert, routing_key, with_record=True):
Expand Down
5 changes: 4 additions & 1 deletion stream_alert/alert_processor/outputs/phantom.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@
from collections import OrderedDict
import os

from stream_alert.alert_processor import LOGGER
from stream_alert.alert_processor.outputs.output_base import (
OutputDispatcher,
OutputProperty,
OutputRequestFailure,
StreamAlertOutput
)
from stream_alert.shared.logger import get_logger


LOGGER = get_logger(__name__)


@StreamAlertOutput
Expand Down
5 changes: 4 additions & 1 deletion stream_alert/alert_processor/outputs/slack.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@
import cgi
from collections import OrderedDict

from stream_alert.alert_processor import LOGGER
from stream_alert.alert_processor.outputs.output_base import (
OutputDispatcher,
OutputProperty,
OutputRequestFailure,
StreamAlertOutput
)
from stream_alert.shared.logger import get_logger


LOGGER = get_logger(__name__)


@StreamAlertOutput
Expand Down
17 changes: 0 additions & 17 deletions stream_alert/apps/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,6 @@
from stream_alert.apps.exceptions import AppException


# Create a package level logger to import
LEVEL = os.environ.get('LOGGER_LEVEL', 'INFO').upper()

# Cast integer levels to avoid a ValueError
if LEVEL.isdigit():
LEVEL = int(LEVEL)

logging.basicConfig(format='%(name)s [%(levelname)s]: [%(module)s.%(funcName)s] %(message)s')

LOGGER = logging.getLogger('StreamAlertApp')
try:
LOGGER.setLevel(LEVEL)
except (TypeError, ValueError) as err:
LOGGER.setLevel('INFO')
LOGGER.error('Defaulting to INFO logging: %s', err)


class StreamAlertApp(object):
"""Class to be used as a decorator to register all AppIntegration subclasses"""
_apps = {}
Expand Down
3 changes: 2 additions & 1 deletion stream_alert/apps/_apps/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""Import some package level items to make implementing subclasses a bit nicer"""
from stream_alert.apps import LOGGER, StreamAlertApp
from stream_alert.apps import StreamAlertApp
from stream_alert.apps.app_base import AppIntegration, safe_timeout
from stream_alert.shared.logger import get_logger
5 changes: 4 additions & 1 deletion stream_alert/apps/_apps/aliyun.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
from aliyunsdkcore.acs_exception.exceptions import ServerException, ClientException
from aliyunsdkactiontrail.request.v20171204 import LookupEventsRequest

from . import AppIntegration, LOGGER, StreamAlertApp
from . import AppIntegration, StreamAlertApp, get_logger


LOGGER = get_logger(__name__)


@StreamAlertApp
Expand Down
5 changes: 4 additions & 1 deletion stream_alert/apps/_apps/box.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
from boxsdk.object.events import EnterpriseEventsStreamType
from requests.exceptions import ConnectionError

from . import AppIntegration, LOGGER, safe_timeout, StreamAlertApp
from . import AppIntegration, StreamAlertApp, get_logger, safe_timeout


LOGGER = get_logger(__name__)


@StreamAlertApp
Expand Down
5 changes: 4 additions & 1 deletion stream_alert/apps/_apps/duo.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@

import requests

from . import AppIntegration, LOGGER, StreamAlertApp
from . import AppIntegration, StreamAlertApp, get_logger


LOGGER = get_logger(__name__)


class DuoApp(AppIntegration):
Expand Down
6 changes: 5 additions & 1 deletion stream_alert/apps/_apps/gsuite.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@
import apiclient
from oauth2client import client, service_account

from . import AppIntegration, LOGGER, StreamAlertApp
from . import AppIntegration, StreamAlertApp, get_logger


LOGGER = get_logger(__name__)


# Disable noisy google api client logger
logging.getLogger('googleapiclient.discovery_cache').setLevel(logging.ERROR)
Expand Down
5 changes: 4 additions & 1 deletion stream_alert/apps/_apps/onelogin.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
"""
import re

from . import AppIntegration, LOGGER, StreamAlertApp
from . import AppIntegration, StreamAlertApp, get_logger


LOGGER = get_logger(__name__)


@StreamAlertApp
Expand Down
6 changes: 5 additions & 1 deletion stream_alert/apps/_apps/salesforce.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,16 @@
import backoff
import requests

from . import AppIntegration, LOGGER, StreamAlertApp
from . import AppIntegration, StreamAlertApp, get_logger


LOGGER = get_logger(__name__)


class SalesforceAppError(Exception):
"""Salesforce App Error class"""


class SalesforceApp(AppIntegration):
"""Salesforce StreamAlert Base App

Expand Down
5 changes: 4 additions & 1 deletion stream_alert/apps/_apps/slack.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
import re
import time

from . import AppIntegration, LOGGER, StreamAlertApp
from . import AppIntegration, StreamAlertApp, get_logger


LOGGER = get_logger(__name__)


class SlackApp(AppIntegration):
Expand Down
5 changes: 4 additions & 1 deletion stream_alert/apps/app_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@
from botocore.exceptions import ClientError
import requests

from stream_alert.apps import LOGGER
from stream_alert.apps.config import AppConfig
from stream_alert.apps.batcher import Batcher
from stream_alert.shared.logger import get_logger


LOGGER = get_logger(__name__)


def _report_time(func):
Expand Down
5 changes: 4 additions & 1 deletion stream_alert/apps/batcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@
import boto3
from botocore.exceptions import ClientError

from stream_alert.apps import LOGGER
from stream_alert.shared.logger import get_logger


LOGGER = get_logger(__name__)


class Batcher(object):
Expand Down
Loading