Skip to content
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
113 changes: 95 additions & 18 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,32 +1,109 @@
*.py[co]
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# Packages
*.egg
*.egg-info
dist
build
eggs
parts
var
sdist
develop-eggs
# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.tox
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/

#Translations
# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

#Mr Developer
.mr.developer.cfg
# PyBuilder
target/

# virutalenvs
# Jupyter Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
env*/
venv*/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/

# debug stuff
test.py
# Intellij
.idea
22 changes: 17 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Stackify API for Python
=======
=======================

[Stackify](https://stackify.com) support for Python programs.

Expand Down Expand Up @@ -35,23 +35,35 @@ export STACKIFY_API_KEY=******

These options can also be provided in your code:
```python
# Standard API
import stackify

logger = stackify.getLogger(application="MyApp", environment="Dev", api_key=******)
logger.warning('Something happened')
```

```python
# Python Logging Integration
import logging
import stackify

# your existing logging
logger = logging.getLogger()
...

stackify_handler = stackify.StackifyHandler(application="MyApp", environment="Dev", api_key=******)
logger.addHandler(stackify_handler)

logger.warning('Something happened')
```

## Usage

stackify-python handles uploads in batches of 100 messages at a time on another thread.
When your program exits, it will shut the thread down and upload the remaining messages.

Stackify can store extra data along with your log message:
```python
import stackify

logger = stackify.getLogger()

try:
user_string = raw_input("Enter a number: ")
print("You entered", int(user_string))
Expand Down
5 changes: 5 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
mock==2.0.0
pytest==4.3.0
pytest-cov==2.6.1
requests==2.21.0
retrying==1.3.3
23 changes: 23 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[flake8]
ignore = E501, W605
exclude =
.git,
__pycache__,
build,
dist,
env*,
venv*,
setup.cfg,
README.md,
LICENSE.txt,
requirements.txt,


[coverage:run]
include =
stackify/*
omit =
*tests*

[tool:pytest]
python_files=tests.py test.py test_*.py *_test.py tests_*.py *_tests.py
33 changes: 16 additions & 17 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

try:
from pypandoc import convert
read_md = lambda f: convert(f, 'rst')
read_md = lambda f: convert(f, 'rst') # noqa
except ImportError:
print('warning: pypandoc module not found, could not convert Markdown to RST')
read_md = lambda f: open(f).read()
read_md = lambda f: open(f).read() # noqa

version_re = re.compile(r'__version__\s+=\s+(.*)')

Expand All @@ -17,26 +17,25 @@
version = ast.literal_eval(version_re.search(f).group(1))

setup(
name = 'stackify',
version = version,
author = 'Matthew Thompson',
author_email = 'chameleonator@gmail.com',
packages = ['stackify'],
url = 'https://github.com/stackify/stackify-api-python',
license = open('LICENSE.txt').readline(),
description = 'Stackify API for Python',
long_description = read_md('README.md'),
download_url = 'https://github.com/stackify/stackify-api-python/tarball/0.0.1',
keywords = ['logging', 'stackify', 'exception'],
name='stackify-api-python',
version=version,
author='Stackify',
author_email='support@stackify.com',
packages=['stackify'],
url='https://github.com/stackify/stackify-api-python',
license=open('LICENSE.txt').readline(),
description='Stackify API for Python',
long_description=read_md('README.md'),
download_url='https://github.com/stackify/stackify-api-python/tarball/0.0.1',
keywords=['logging', 'stackify', 'exception'],
classifiers=["Programming Language :: Python"],
install_requires = [
install_requires=[
'retrying>=1.2.3',
'requests>=2.4.1'
],
test_suite = 'tests',
tests_requires = [
test_suite='tests',
tests_requires=[
'mock>=1.0.1',
'nose==1.3.4'
]
)

35 changes: 7 additions & 28 deletions stackify/__init__.py
Original file line number Diff line number Diff line change
@@ -1,45 +1,23 @@
"""
Stackify Python API
"""

__version__ = '0.0.1'


API_URL = 'https://api.stackify.com'

READ_TIMEOUT = 5000

MAX_BATCH = 100

QUEUE_SIZE = 1000

import logging
import inspect
import atexit

DEFAULT_LEVEL = logging.ERROR

LOGGING_LEVELS = {
logging.CRITICAL: 'CRITICAL',
logging.ERROR: 'ERROR',
logging.WARNING: 'WARNING',
logging.INFO: 'INFO',
logging.DEBUG: 'DEBUG',
logging.NOTSET: 'NOTSET'
}
from stackify.application import ApiConfiguration # noqa
from stackify.constants import DEFAULT_LEVEL
from stackify.handler import StackifyHandler


class NullHandler(logging.Handler):
def emit(self, record):
pass

logging.getLogger(__name__).addHandler(NullHandler())


from stackify.application import ApiConfiguration
from stackify.http import HTTPClient

from stackify.handler import StackifyHandler
logging.getLogger(__name__).addHandler(NullHandler())


def getLogger(name=None, auto_shutdown=True, basic_config=True, **kwargs):
Expand Down Expand Up @@ -77,8 +55,6 @@ def getLogger(name=None, auto_shutdown=True, basic_config=True, **kwargs):
if not [isinstance(x, StackifyHandler) for x in logger.handlers]:
internal_logger = logging.getLogger(__name__)
internal_logger.debug('Creating handler for logger %s', name)
handler = StackifyHandler(**kwargs)
logger.addHandler(handler)

if auto_shutdown:
internal_logger.debug('Registering atexit callback')
Expand All @@ -87,6 +63,9 @@ def getLogger(name=None, auto_shutdown=True, basic_config=True, **kwargs):
if logger.getEffectiveLevel() == logging.NOTSET:
logger.setLevel(DEFAULT_LEVEL)

handler = StackifyHandler(ensure_at_exit=not auto_shutdown, **kwargs)
logger.addHandler(handler)

handler.listener.start()

return logger
Expand Down
5 changes: 2 additions & 3 deletions stackify/application.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import socket
import os

from stackify import API_URL
from stackify.constants import API_URL
from stackify.formats import JSONObject


Expand Down Expand Up @@ -32,8 +32,7 @@ def arg_or_env(name, args, default=None):
if default:
return default
else:
raise NameError('You must specify the keyword argument {0} or '
'environment variable {1}'.format(name, env_name))
raise NameError('You must specify the keyword argument {0} or environment variable {1}'.format(name, env_name))


def get_configuration(**kwargs):
Expand Down
21 changes: 21 additions & 0 deletions stackify/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import logging


API_URL = 'https://api.stackify.com'
IDENTIFY_URL = '/Metrics/IdentifyApp'
LOG_SAVE_URL = '/Log/Save'
API_REQUEST_INTERVAL_IN_SEC = 30

MAX_BATCH = 100
QUEUE_SIZE = 1000
READ_TIMEOUT = 5000

LOGGING_LEVELS = {
logging.CRITICAL: 'CRITICAL',
logging.ERROR: 'ERROR',
logging.WARNING: 'WARNING',
logging.INFO: 'INFO',
logging.DEBUG: 'DEBUG',
logging.NOTSET: 'NOTSET'
}
DEFAULT_LEVEL = logging.ERROR
Loading