Skip to content

Commit

Permalink
Merge pull request #5 from erayerdin/development
Browse files Browse the repository at this point in the history
v0.1.0b1
  • Loading branch information
erayerdin committed May 14, 2019
2 parents 3882859 + f598b14 commit e088f86
Show file tree
Hide file tree
Showing 17 changed files with 389 additions and 8 deletions.
70 changes: 70 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ dist: xenial

jobs:
include:
#########
# Style #
#########
- stage: Style Checking
python: '3.7'
install:
Expand All @@ -17,6 +20,11 @@ jobs:
- tgcli bot send -r $TELEGRAM_RECEIVER message "🥂 Style check passed for \`tglogger\`."
after_failure:
- tgcli bot send -r $TELEGRAM_RECEIVER message "✂️💥 Style checking failed for \`tglogger\`. [See](https://travis-ci.com/erayerdin/tglogger)."

##########
# Python #
##########
# 3.5 #
- stage: Testing
python: '3.5'
install:
Expand All @@ -29,6 +37,7 @@ jobs:
- tgcli bot send -r $TELEGRAM_RECEIVER message "🍻 \`tglogger\` works in Python 3.5."
after_failure:
- tgcli bot send -r $TELEGRAM_RECEIVER message "📦💥 \`tglogger\` failed in Python 3.5. [See](https://travis-ci.com/erayerdin/tglogger)."
# 3.6 #
- stage: Testing
python: '3.6'
install:
Expand All @@ -41,6 +50,7 @@ jobs:
- tgcli bot send -r $TELEGRAM_RECEIVER message "🍻 \`tglogger\` works in Python3.6."
after_failure:
- tgcli bot send -r $TELEGRAM_RECEIVER message "📦💥 \`tglogger\` failed in Python 3.6. [See](https://travis-ci.com/erayerdin/tglogger)."
# 3.7 #
- stage: Testing
python: '3.7'
install:
Expand All @@ -53,6 +63,66 @@ jobs:
- tgcli bot send -r $TELEGRAM_RECEIVER message "🍻 \`tglogger\` works in Python 3.7."
after_failure:
- tgcli bot send -r $TELEGRAM_RECEIVER message "📦💥 \`tglogger\` failed in Python 3.7. [See](https://travis-ci.com/erayerdin/tglogger)."

##########
# Django #
##########
# 1.11 #
- stage: Testing with Django
python: '3.5'
install:
- pip install -r requirements.txt
- pip install -r dev.requirements.txt
- pip install tgcli "django>=1.11<2.0" --upgrade
script:
- pytest --ds=django_project.settings
after_success:
- tgcli bot send -r $TELEGRAM_RECEIVER message "🍻 \`tglogger\` works in Django 1.11."
after_failure:
- tgcli bot send -r $TELEGRAM_RECEIVER message "📦💥 \`tglogger\` failed in Django 1.11. [See](https://travis-ci.com/erayerdin/tglogger)."
# 2.0 #
- stage: Testing with Django
python: '3.5'
install:
- pip install -r requirements.txt
- pip install -r dev.requirements.txt
- pip install tgcli "django>=2.0<2.1" --upgrade
script:
- pytest --ds=django_project.settings
after_success:
- tgcli bot send -r $TELEGRAM_RECEIVER message "🍻 \`tglogger\` works in Django 2.0."
after_failure:
- tgcli bot send -r $TELEGRAM_RECEIVER message "📦💥 \`tglogger\` failed in Django 2.0. [See](https://travis-ci.com/erayerdin/tglogger)."
# 2.1 #
- stage: Testing with Django
python: '3.5'
install:
- pip install -r requirements.txt
- pip install -r dev.requirements.txt
- pip install tgcli "django>=2.1<2.2" --upgrade
script:
- pytest --ds=django_project.settings
after_success:
- tgcli bot send -r $TELEGRAM_RECEIVER message "🍻 \`tglogger\` works in Django 2.1."
after_failure:
- tgcli bot send -r $TELEGRAM_RECEIVER message "📦💥 \`tglogger\` failed in Django 2.1. [See](https://travis-ci.com/erayerdin/tglogger)."
# 2.2 #
- stage: Testing with Django
python: '3.5'
install:
- pip install -r requirements.txt
- pip install -r dev.requirements.txt
- pip install tgcli "django>=2.2<2.3" --upgrade
script:
- pytest --ds=django_project.settings
after_success:
- tgcli bot send -r $TELEGRAM_RECEIVER message "🍻 \`tglogger\` works in Django 2.2."
after_failure:
- tgcli bot send -r $TELEGRAM_RECEIVER message "📦💥 \`tglogger\` failed in Django 2.2. [See](https://travis-ci.com/erayerdin/tglogger)."

##############
# Deployment #
##############
- stage: Covering / Deploy
python: '3.7'
install:
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [v0.1.0b1] - 2019-05-14
### Added
- Explicit Django support

### Changed
- Optimized Django parts

## [v0.1.0a3] - 2019-05-13
### Added
- `_TEMPLATE` to `TelegramFormatter`
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
[![PyPI](https://img.shields.io/pypi/status/tglogger.svg?style=flat-square&logo=python&logoColor=white)][pypi_url]
[![PyPI](https://img.shields.io/pypi/dm/tglogger.svg?style=flat-square&logo=python&logoColor=white)][pypi_url]
[![PyPI](https://img.shields.io/pypi/pyversions/tglogger.svg?style=flat-square&logo=python&logoColor=white)][pypi_url]
[![PyPI - Django Version](https://img.shields.io/pypi/djversions/tglogger.svg?style=flat-square)][pypi_url]
[![PyPI](https://img.shields.io/pypi/l/tglogger.svg?style=flat-square)][pypi_url]
[![](https://img.shields.io/readthedocs/tglogger.svg?style=flat-square)](https://tglogger.readthedocs.io/en/latest/)
[![Telegram](https://img.shields.io/badge/telegram-%40erayerdin-%2332afed.svg?style=flat-square&logo=telegram&logoColor=white)](https://t.me/erayerdin)
Expand Down
1 change: 1 addition & 0 deletions dev.requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ requests_mock==1.6.0
codecov==2.0.15
mkdocs==1.0.4
mkdocs-material==4.2.0
pytest-django==3.4.8
Empty file added django_project/__init__.py
Empty file.
120 changes: 120 additions & 0 deletions django_project/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
"""
Django settings for django_project project.
Generated by 'django-admin startproject' using Django 2.2.1.
For more information on this file, see
https://docs.djangoproject.com/en/2.2/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.2/ref/settings/
"""

import os

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '&t$*1poq6&_ke09iy1rronlkp&dj3m_^&v26-tf#iy(h&0!d1q'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'django_project.urls'

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]

WSGI_APPLICATION = 'django_project.wsgi.application'


# Database
# https://docs.djangoproject.com/en/2.2/ref/settings/#databases

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}


# Password validation
# https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]


# Internationalization
# https://docs.djangoproject.com/en/2.2/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.2/howto/static-files/

STATIC_URL = '/static/'
21 changes: 21 additions & 0 deletions django_project/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"""django_project URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/2.2/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path

urlpatterns = [
path('admin/', admin.site.urls),
]
16 changes: 16 additions & 0 deletions django_project/wsgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
WSGI config for django_project project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/2.2/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'django_project.settings')

application = get_wsgi_application()
49 changes: 49 additions & 0 deletions docs/django.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Django Integration

You can integrate tglogger with Django as well so as to get live logging
records. See the example `LOGGING` settings below:

```python
LOGGING = {
# ...
"formatters": {
# ...
"telegram_formatter": {
"()", "tglogger.formatter.TelegramFormatter"
},
# ...
},
# ...
"handlers": {
# ...
"telegram_handler": {
"class": "tglogger.formatter.TelegramHandler",
"formatter": "telegram_formatter",
"bot_token": "BOT_TOKEN", # replace it with your token
"receiver": "CHAT_ID", # chat id to send message to
},
# ...
},
# ...
}
```

!!! tip
Instead of explicitly defining `bot_token` and `receiver` in the
configuration, you can set `TELEGRAM_BOT_TOKEN` and `TELEGRAM_RECEIVER`
environment variables.

The default logging level for `TelegramHandler` is `ERROR`, you can change
this behavior by simply passing `level` to the handler in the `LOGGING`
*dictConfig*.

```python
# assuming you have set TELEGRAM_BOT_TOKEN and TELEGRAM_RECEIVER environment variables
"handlers": {
"telegram_handler": {
"class": "tglogger.formatter.TelegramHandler",
"formatter": "telegram_formatter",
"level", "INFO",
},
},
```
21 changes: 21 additions & 0 deletions manage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys


def main():
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'django_project.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)


if __name__ == '__main__':
main()
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ markdown_extensions:
nav:
- Home: index.md
- Getting Started: getting-started.md
- Django Integration: django.md
4 changes: 4 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Framework :: Django :: 1.11",
"Framework :: Django :: 2.0",
"Framework :: Django :: 2.1",
"Framework :: Django :: 2.2",
"Topic :: Communications :: Chat",
"Topic :: System :: Logging",
"Topic :: System :: Monitoring",
Expand Down

0 comments on commit e088f86

Please sign in to comment.