Skip to content

Commit

Permalink
Merge pull request #154 from cartologic/hisham-dev
Browse files Browse the repository at this point in the history
add log_handler module
  • Loading branch information
ahmednoureldeen authored Apr 24, 2018
2 parents 861f1c4 + bcef5ea commit 2879792
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 72 deletions.
15 changes: 2 additions & 13 deletions cartoview/app_manager/api.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
from __future__ import (absolute_import, division, print_function,
unicode_literals)

import logging
import warnings
from builtins import *
from sys import stdout

from django.conf.urls import include, patterns, url
from django.shortcuts import render
Expand All @@ -13,19 +10,11 @@
from tastypie.utils import trailing_slash

from .serializers import HTMLSerializer

from cartoview.log_handler import get_logger
logger = get_logger(__name__)
standard_library.install_aliases()


formatter = logging.Formatter(
'[%(asctime)s] p%(process)s { %(name)s %(pathname)s:%(lineno)d}\
%(levelname)s - %(message)s', '%m-%d %H:%M:%S')
logger = logging.getLogger(__name__)
handler = logging.StreamHandler(stdout)
handler.setFormatter(formatter)
logger.addHandler(handler)


class BaseApi(TastypieApi):
"""
A version of the Api that doesn't require a name.
Expand Down
15 changes: 6 additions & 9 deletions cartoview/app_manager/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,11 @@
except Exception:
pass
from .models import App, AppStore, AppType
from cartoview.log_handler import get_logger
logger = get_logger(__name__)
install_app_batch = getattr(settings, 'INSTALL_APP_BAT', None)
standard_library.install_aliases()
reload(pkg_resources)
formatter = logging.Formatter(
'[%(asctime)s] p%(process)s { %(name)s %(pathname)s:%(lineno)d} \
%(levelname)s - %(message)s', '%m-%d %H:%M:%S')
logger = logging.getLogger(__name__)
handler = logging.StreamHandler(stdout)
handler.setFormatter(formatter)
logger.addHandler(handler)
current_folder = os.path.abspath(os.path.dirname(__file__))
temp_dir = os.path.join(current_folder, 'temp')

Expand All @@ -50,10 +45,12 @@ def save_pending_app_to_finlize(self):
with open(settings.PENDING_APPS, 'wb') as outfile:
if 'fcntl' in globals():
fcntl.flock(outfile, fcntl.LOCK_EX | fcntl.LOCK_NB)
yaml.dump(self.apps_to_finlize, outfile, default_flow_style=False)
yaml.dump(self.apps_to_finlize, outfile,
default_flow_style=False)
fcntl.flock(outfile, fcntl.LOCK_UN)
else:
yaml.dump(self.apps_to_finlize, outfile, default_flow_style=False)
yaml.dump(self.apps_to_finlize, outfile,
default_flow_style=False)
self.apps_to_finlize = []

def restart_server(self):
Expand Down
10 changes: 2 additions & 8 deletions cartoview/app_manager/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,11 @@
from geonode.security.models import (remove_object_permissions)

from .config import AppsConfig
from cartoview.log_handler import get_logger
logger = get_logger(__name__)

standard_library.install_aliases()

formatter = logging.Formatter(
'[%(asctime)s] p%(process)s { %(name)s %(pathname)s:%(lineno)d} \
%(levelname)s - %(message)s', '%m-%d %H:%M:%S')
logger = logging.getLogger(__name__)
handler = logging.StreamHandler(stdout)
handler.setFormatter(formatter)
logger.addHandler(handler)


class AppTypeManager(models.Manager):
def without_apps_duplication(self):
Expand Down
13 changes: 2 additions & 11 deletions cartoview/app_manager/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,20 @@
unicode_literals)

import importlib
import logging
import os
import sys
from builtins import *
from sys import stdout

from future import standard_library
from past.builtins import execfile

from cartoview.app_manager.config import AppsConfig
from cartoview.app_manager.helpers import (change_path_permission,
create_direcotry)
from cartoview.log_handler import get_logger
logger = get_logger(__name__)

standard_library.install_aliases()


formatter = logging.Formatter(
'[%(asctime)s] p%(process)s { %(name)s %(pathname)s:%(lineno)d} \
%(levelname)s - %(message)s', '%m-%d %H:%M:%S')
logger = logging.getLogger(__name__)
handler = logging.StreamHandler(stdout)
handler.setFormatter(formatter)
logger.addHandler(handler)
# BASE_DIR must be defined in project.settings
APPS_DIR = os.path.abspath(os.path.join(BASE_DIR, "apps"))
if not os.path.exists(APPS_DIR):
Expand Down
12 changes: 2 additions & 10 deletions cartoview/app_manager/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
import abc
import importlib
import json
import logging
import os
from builtins import *
from sys import stdout
from django.shortcuts import get_object_or_404
from urllib.parse import urljoin
from .decorators import (can_change_app_instance, can_view_app_instance,
Expand Down Expand Up @@ -45,17 +43,11 @@
from .installer import AppInstaller
from .models import App, AppInstance
from .utils import AppsThumbnail, resolve_appinstance
from cartoview.log_handler import get_logger
logger = get_logger(__name__)

standard_library.install_aliases()


formatter = logging.Formatter(
'[%(asctime)s] p%(process)s { %(name)s %(pathname)s:%(lineno)d} \
%(levelname)s - %(message)s', '%m-%d %H:%M:%S')
logger = logging.getLogger(__name__)
handler = logging.StreamHandler(stdout)
handler.setFormatter(formatter)
logger.addHandler(handler)
_PERMISSION_MSG_DELETE = _("You are not permitted to delete this document")
_PERMISSION_MSG_GENERIC = _("You do not have permissions for this document.")
_PERMISSION_MSG_MODIFY = _("You are not permitted to modify this document")
Expand Down
10 changes: 3 additions & 7 deletions cartoview/apps_handler/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,15 @@
from django.conf import settings
from django.core.management import call_command
from django.core.management.base import CommandError
from cartoview.log_handler import get_logger
# TODO: find a cross platform function (fcntl is not supported by windows)
try:
import fcntl
except Exception:
pass
pending_yaml = settings.PENDING_APPS
formatter = logging.Formatter(
'[%(asctime)s] p%(process)s { %(name)s %(pathname)s:%(lineno)d} \
%(levelname)s - %(message)s', '%m-%d %H:%M:%S')
logger = logging.getLogger(__name__)
handler = logging.StreamHandler(stdout)
handler.setFormatter(formatter)
logger.addHandler(handler)

logger = get_logger(__name__)


class AppsHandlerConfig(AppConfig):
Expand Down
13 changes: 0 additions & 13 deletions cartoview/cartoview_api/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,6 @@

from django.apps import AppConfig
from django.conf import settings
import os
import logging
from sys import stdout
from django.core.management import call_command
from django.core.management.base import CommandError
pending_yaml = settings.PENDING_APPS
formatter = logging.Formatter(
'[%(asctime)s] p%(process)s { %(name)s %(pathname)s:%(lineno)d} \
%(levelname)s - %(message)s', '%m-%d %H:%M:%S')
logger = logging.getLogger(__name__)
handler = logging.StreamHandler(stdout)
handler.setFormatter(formatter)
logger.addHandler(handler)


class CartoviewAPIConfig(AppConfig):
Expand Down
7 changes: 6 additions & 1 deletion cartoview/cartoview_api/views.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
from django.shortcuts import HttpResponse
from geonode.layers.views import layer_detail
import json
try:
import simplejson as json
except:
import json
import requests
from requests.auth import HTTPBasicAuth
from geonode.layers.views import _resolve_layer, _PERMISSION_MSG_MODIFY
from cartoview.log_handler import get_logger
logger = get_logger(__name__)


def convert_infinty(obj):
Expand Down
13 changes: 13 additions & 0 deletions cartoview/log_handler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from sys import stdout
import logging
formatter = logging.Formatter(
'[%(asctime)s] p%(process)s { %(name)s %(pathname)s:%(lineno)d} \
%(levelname)s - %(message)s', '%m-%d %H:%M:%S')


def get_logger(name=__name__):
logger = logging.getLogger(name)
handler = logging.StreamHandler(stdout)
handler.setFormatter(formatter)
logger.addHandler(handler)
return logger

0 comments on commit 2879792

Please sign in to comment.