Skip to content
This repository has been archived by the owner on Sep 20, 2023. It is now read-only.

Commit

Permalink
Suppress log4j warnings (fix #67)
Browse files Browse the repository at this point in the history
  • Loading branch information
laughingman7743 committed Sep 15, 2018
1 parent 0ff86db commit cf24d2d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
5 changes: 3 additions & 2 deletions pyathenajdbc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
ATHENA_JAR)
ATHENA_DRIVER_CLASS_NAME = 'com.simba.athena.jdbc.Driver'
ATHENA_CONNECTION_STRING = 'jdbc:awsathena://AwsRegion={region};'
LOG4J_PROPERTIES = 'log4j.properties'


class DBAPITypeObject:
Expand Down Expand Up @@ -60,9 +61,9 @@ def __eq__(self, other):
def connect(s3_staging_dir=None, access_key=None, secret_key=None,
region_name=None, schema_name='default', profile_name=None, credential_file=None,
jvm_path=None, jvm_options=None, converter=None, formatter=None,
driver_path=None, **kwargs):
driver_path=None, log4j_conf=None, **kwargs):
from pyathenajdbc.connection import Connection
return Connection(s3_staging_dir, access_key, secret_key,
region_name, schema_name, profile_name, credential_file,
jvm_path, jvm_options, converter, formatter,
driver_path, **kwargs)
driver_path, log4j_conf, **kwargs)
20 changes: 14 additions & 6 deletions pyathenajdbc/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
import jpype
from future.utils import iteritems

from pyathenajdbc import (ATHENA_CONNECTION_STRING, ATHENA_DRIVER_CLASS_NAME, ATHENA_JAR)
from pyathenajdbc import (ATHENA_CONNECTION_STRING, ATHENA_DRIVER_CLASS_NAME,
ATHENA_JAR, LOG4J_PROPERTIES)
from pyathenajdbc.converter import JDBCTypeConverter
from pyathenajdbc.cursor import Cursor
from pyathenajdbc.error import NotSupportedError, ProgrammingError
Expand All @@ -21,11 +22,12 @@
class Connection(object):

_ENV_S3_STAGING_DIR = 'AWS_ATHENA_S3_STAGING_DIR'
_BASE_PATH = os.path.dirname(os.path.abspath(__file__))

def __init__(self, s3_staging_dir=None, access_key=None, secret_key=None,
region_name=None, schema_name='default', profile_name=None, credential_file=None,
jvm_path=None, jvm_options=None, converter=None, formatter=None,
driver_path=None, **driver_kwargs):
driver_path=None, log4j_conf=None, **driver_kwargs):
if s3_staging_dir:
self.s3_staging_dir = s3_staging_dir
else:
Expand Down Expand Up @@ -63,7 +65,7 @@ def __init__(self, s3_staging_dir=None, access_key=None, secret_key=None,
self.region_name = session.get_config_variable('region')
assert self.region_name, 'Required argument `region_name` not found.'

self._start_jvm(jvm_path, jvm_options, driver_path)
self._start_jvm(jvm_path, jvm_options, driver_path, log4j_conf)

props = self._build_driver_args(**driver_kwargs)
jpype.JClass(ATHENA_DRIVER_CLASS_NAME)
Expand All @@ -75,14 +77,20 @@ def __init__(self, s3_staging_dir=None, access_key=None, secret_key=None,

@classmethod
@synchronized
def _start_jvm(cls, jvm_path, jvm_options, driver_path):
def _start_jvm(cls, jvm_path, jvm_options, driver_path, log4j_conf):
if jvm_path is None:
jvm_path = jpype.get_default_jvm_path()
if driver_path is None:
driver_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), ATHENA_JAR)
driver_path = os.path.join(cls._BASE_PATH, ATHENA_JAR)
if log4j_conf is None:
log4j_conf = os.path.join(cls._BASE_PATH, LOG4J_PROPERTIES)
if not jpype.isJVMStarted():
_logger.debug('JVM path: %s', jvm_path)
args = ['-server', '-Djava.class.path={0}'.format(driver_path)]
args = [
'-server',
'-Djava.class.path={0}'.format(driver_path),
'-Dlog4j.configuration=file:{0}'.format(log4j_conf)
]
if jvm_options:
args.extend(jvm_options)
_logger.debug('JVM args: %s', args)
Expand Down
2 changes: 2 additions & 0 deletions pyathenajdbc/log4j.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
log4j.rootLogger=FATAL, null
log4j.appender.null=com.simba.athena.shaded.apache.log4j.varia.NullAppender
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def run(self):
package_data={
'': ['LICENSE', '*.rst'],
'jdbc': ['*.txt'],
_PACKAGE_NAME.lower(): ['*.jar'],
_PACKAGE_NAME.lower(): ['*.jar', '*.properties'],
},
install_requires=[
'future',
Expand Down

0 comments on commit cf24d2d

Please sign in to comment.