mirror of
https://github.com/craigerl/aprsd.git
synced 2024-11-17 13:51:54 -05:00
Moved logging to log for wsgi.py
Added wsgi.py to be used with gunicorn to start aprsd's web admin interface. gunicorn -b :8080 "aprsd.wsgi:app"
This commit is contained in:
parent
565ffe3f72
commit
35d41582ee
14
README.rst
14
README.rst
@ -289,6 +289,20 @@ LOCATION
|
|||||||
AND... ping, fortune, time.....
|
AND... ping, fortune, time.....
|
||||||
|
|
||||||
|
|
||||||
|
Web Admin Interface
|
||||||
|
===================
|
||||||
|
To start the web admin interface, You have to install gunicorn in your virtualenv that already has aprsd installed.
|
||||||
|
|
||||||
|
::
|
||||||
|
|
||||||
|
source <path to APRSD's virtualenv>/bin/activate
|
||||||
|
pip install gunicorn
|
||||||
|
gunicorn --bind 0.0.0.0:8080 "aprsd.wsgi:app"
|
||||||
|
|
||||||
|
The web admin interface will be running on port 8080 on the local machine. http://localhost:8080
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Development
|
Development
|
||||||
===========
|
===========
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ from werkzeug.security import check_password_hash, generate_password_hash
|
|||||||
|
|
||||||
import aprsd
|
import aprsd
|
||||||
from aprsd import cli_helper, client, conf, packets, plugin, threads
|
from aprsd import cli_helper, client, conf, packets, plugin, threads
|
||||||
from aprsd.logging import rich as aprsd_logging
|
from aprsd.log import rich as aprsd_logging
|
||||||
from aprsd.rpc import client as aprsd_rpc_client
|
from aprsd.rpc import client as aprsd_rpc_client
|
||||||
|
|
||||||
|
|
||||||
@ -335,7 +335,7 @@ def init_flask(loglevel, quiet):
|
|||||||
return socketio, flask_app
|
return socketio, flask_app
|
||||||
|
|
||||||
|
|
||||||
def create_app(config_file=None, log_level=None, gunicorn=False):
|
def create_app(config_file=None, log_level=None):
|
||||||
global socketio
|
global socketio
|
||||||
global app
|
global app
|
||||||
|
|
||||||
@ -351,12 +351,9 @@ def create_app(config_file=None, log_level=None, gunicorn=False):
|
|||||||
if not log_level:
|
if not log_level:
|
||||||
log_level = CONF.logging.log_level
|
log_level = CONF.logging.log_level
|
||||||
|
|
||||||
if gunicorn:
|
|
||||||
socketio, app = init_flask(log_level, False)
|
socketio, app = init_flask(log_level, False)
|
||||||
setup_logging(app, log_level, False)
|
setup_logging(app, log_level, False)
|
||||||
return app
|
return app
|
||||||
else:
|
|
||||||
return socketio
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "aprsd.flask":
|
if __name__ == "aprsd.flask":
|
||||||
|
@ -8,7 +8,7 @@ from oslo_config import cfg
|
|||||||
|
|
||||||
import aprsd
|
import aprsd
|
||||||
from aprsd import conf # noqa: F401
|
from aprsd import conf # noqa: F401
|
||||||
from aprsd.logging import log
|
from aprsd.log import log
|
||||||
from aprsd.utils import trace
|
from aprsd.utils import trace
|
||||||
|
|
||||||
|
|
||||||
|
@ -144,7 +144,7 @@ class APRSISClient(Client):
|
|||||||
try:
|
try:
|
||||||
LOG.info("Creating aprslib client")
|
LOG.info("Creating aprslib client")
|
||||||
aprs_client = aprsis.Aprsdis(user, passwd=password, host=host, port=port)
|
aprs_client = aprsis.Aprsdis(user, passwd=password, host=host, port=port)
|
||||||
# Force the logging to be the same
|
# Force the log to be the same
|
||||||
aprs_client.logger = LOG
|
aprs_client.logger = LOG
|
||||||
aprs_client.connect()
|
aprs_client.connect()
|
||||||
connected = True
|
connected = True
|
||||||
|
@ -17,7 +17,7 @@ from aprsd.rpc import client as rpc_client
|
|||||||
|
|
||||||
|
|
||||||
# setup the global logger
|
# setup the global logger
|
||||||
# logging.basicConfig(level=logging.DEBUG) # level=10
|
# log.basicConfig(level=log.DEBUG) # level=10
|
||||||
LOG = logging.getLogger("APRSD")
|
LOG = logging.getLogger("APRSD")
|
||||||
CONF = cfg.CONF
|
CONF = cfg.CONF
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ from aprsd.rpc import client as aprsd_rpc_client
|
|||||||
|
|
||||||
|
|
||||||
# setup the global logger
|
# setup the global logger
|
||||||
# logging.basicConfig(level=logging.DEBUG) # level=10
|
# log.basicConfig(level=log.DEBUG) # level=10
|
||||||
CONF = cfg.CONF
|
CONF = cfg.CONF
|
||||||
LOG = logging.getLogger("APRSD")
|
LOG = logging.getLogger("APRSD")
|
||||||
console = Console()
|
console = Console()
|
||||||
|
@ -22,7 +22,7 @@ from aprsd.threads import rx
|
|||||||
|
|
||||||
|
|
||||||
# setup the global logger
|
# setup the global logger
|
||||||
# logging.basicConfig(level=logging.DEBUG) # level=10
|
# log.basicConfig(level=log.DEBUG) # level=10
|
||||||
LOG = logging.getLogger("APRSD")
|
LOG = logging.getLogger("APRSD")
|
||||||
CONF = cfg.CONF
|
CONF = cfg.CONF
|
||||||
console = Console()
|
console = Console()
|
||||||
|
@ -22,7 +22,7 @@ import wrapt
|
|||||||
|
|
||||||
import aprsd
|
import aprsd
|
||||||
from aprsd import cli_helper, client, conf, packets, stats, threads, utils
|
from aprsd import cli_helper, client, conf, packets, stats, threads, utils
|
||||||
from aprsd.logging import rich as aprsd_logging
|
from aprsd.log import rich as aprsd_logging
|
||||||
from aprsd.main import cli
|
from aprsd.main import cli
|
||||||
from aprsd.threads import rx, tx
|
from aprsd.threads import rx, tx
|
||||||
from aprsd.utils import objectstore, trace
|
from aprsd.utils import objectstore, trace
|
||||||
|
@ -28,7 +28,7 @@ def set_lib_defaults():
|
|||||||
|
|
||||||
|
|
||||||
def set_log_defaults():
|
def set_log_defaults():
|
||||||
# logging.set_defaults(default_log_levels=logging.get_default_log_levels())
|
# log.set_defaults(default_log_levels=log.get_default_log_levels())
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
"""
|
"""
|
||||||
The options for logging setup
|
The options for log setup
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
"""
|
"""
|
||||||
The options for logging setup
|
The options for log setup
|
||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
@ -33,7 +33,7 @@ logging_opts = [
|
|||||||
cfg.BoolOpt(
|
cfg.BoolOpt(
|
||||||
"rich_logging",
|
"rich_logging",
|
||||||
default=True,
|
default=True,
|
||||||
help="Enable Rich logging",
|
help="Enable Rich log",
|
||||||
),
|
),
|
||||||
cfg.StrOpt(
|
cfg.StrOpt(
|
||||||
"logfile",
|
"logfile",
|
||||||
@ -45,6 +45,12 @@ logging_opts = [
|
|||||||
default=DEFAULT_LOG_FORMAT,
|
default=DEFAULT_LOG_FORMAT,
|
||||||
help="Log file format, unless rich_logging enabled.",
|
help="Log file format, unless rich_logging enabled.",
|
||||||
),
|
),
|
||||||
|
cfg.StrOpt(
|
||||||
|
"log_level",
|
||||||
|
default="INFO",
|
||||||
|
choices=LOG_LEVELS.keys(),
|
||||||
|
help="Log level for logging of events.",
|
||||||
|
),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ import sys
|
|||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
|
|
||||||
from aprsd import conf
|
from aprsd import conf
|
||||||
from aprsd.logging import rich as aprsd_logging
|
from aprsd.log import rich as aprsd_logging
|
||||||
|
|
||||||
|
|
||||||
CONF = cfg.CONF
|
CONF = cfg.CONF
|
||||||
@ -15,8 +15,8 @@ LOG = logging.getLogger("APRSD")
|
|||||||
logging_queue = queue.Queue()
|
logging_queue = queue.Queue()
|
||||||
|
|
||||||
|
|
||||||
# Setup the logging faciility
|
# Setup the log faciility
|
||||||
# to disable logging to stdout, but still log to file
|
# to disable log to stdout, but still log to file
|
||||||
# use the --quiet option on the cmdln
|
# use the --quiet option on the cmdln
|
||||||
def setup_logging(loglevel, quiet):
|
def setup_logging(loglevel, quiet):
|
||||||
log_level = conf.log.LOG_LEVELS[loglevel]
|
log_level = conf.log.LOG_LEVELS[loglevel]
|
@ -130,7 +130,7 @@ class APRSDRichHandler(RichHandler):
|
|||||||
"""Render log for display.
|
"""Render log for display.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
record (LogRecord): logging Record.
|
record (LogRecord): log Record.
|
||||||
traceback (Optional[Traceback]): Traceback instance or None for no Traceback.
|
traceback (Optional[Traceback]): Traceback instance or None for no Traceback.
|
||||||
message_renderable (ConsoleRenderable): Renderable (typically Text) containing log message contents.
|
message_renderable (ConsoleRenderable): Renderable (typically Text) containing log message contents.
|
||||||
|
|
@ -39,7 +39,7 @@ from aprsd import cli_helper, packets, stats, threads, utils
|
|||||||
|
|
||||||
|
|
||||||
# setup the global logger
|
# setup the global logger
|
||||||
# logging.basicConfig(level=logging.DEBUG) # level=10
|
# log.basicConfig(level=log.DEBUG) # level=10
|
||||||
CONF = cfg.CONF
|
CONF = cfg.CONF
|
||||||
LOG = logging.getLogger("APRSD")
|
LOG = logging.getLogger("APRSD")
|
||||||
CONTEXT_SETTINGS = dict(help_option_names=["-h", "--help"])
|
CONTEXT_SETTINGS = dict(help_option_names=["-h", "--help"])
|
||||||
|
@ -666,7 +666,7 @@ class APRSDEmailThread(threads.APRSDThread):
|
|||||||
EmailInfo().delay = 60
|
EmailInfo().delay = 60
|
||||||
|
|
||||||
# reset clock
|
# reset clock
|
||||||
LOG.debug("Done looping over Server.fetch, logging out.")
|
LOG.debug("Done looping over Server.fetch, log out.")
|
||||||
self.past = datetime.datetime.now()
|
self.past = datetime.datetime.now()
|
||||||
try:
|
try:
|
||||||
server.logout()
|
server.logout()
|
||||||
|
@ -4,7 +4,7 @@ import threading
|
|||||||
import wrapt
|
import wrapt
|
||||||
|
|
||||||
from aprsd import threads
|
from aprsd import threads
|
||||||
from aprsd.logging import log
|
from aprsd.log import log
|
||||||
|
|
||||||
|
|
||||||
LOG = logging.getLogger("APRSD")
|
LOG = logging.getLogger("APRSD")
|
||||||
|
12
aprsd/wsgi.py
Normal file
12
aprsd/wsgi.py
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
import logging
|
||||||
|
|
||||||
|
from oslo_config import cfg
|
||||||
|
|
||||||
|
from aprsd import admin_web
|
||||||
|
from aprsd import conf # noqa
|
||||||
|
|
||||||
|
|
||||||
|
CONF = cfg.CONF
|
||||||
|
LOG = logging.getLogger("APRSD")
|
||||||
|
app = None
|
||||||
|
app = admin_web.create_app()
|
@ -30,7 +30,7 @@ class TestSendMessageCommand(unittest.TestCase):
|
|||||||
CONF.admin.user = "admin"
|
CONF.admin.user = "admin"
|
||||||
CONF.admin.password = "password"
|
CONF.admin.password = "password"
|
||||||
|
|
||||||
@mock.patch("aprsd.logging.log.setup_logging")
|
@mock.patch("aprsd.log.log.setup_logging")
|
||||||
def test_no_tocallsign(self, mock_logging):
|
def test_no_tocallsign(self, mock_logging):
|
||||||
"""Make sure we get an error if there is no tocallsign."""
|
"""Make sure we get an error if there is no tocallsign."""
|
||||||
|
|
||||||
@ -47,7 +47,7 @@ class TestSendMessageCommand(unittest.TestCase):
|
|||||||
assert result.exit_code == 2
|
assert result.exit_code == 2
|
||||||
assert "Error: Missing argument 'TOCALLSIGN'" in result.output
|
assert "Error: Missing argument 'TOCALLSIGN'" in result.output
|
||||||
|
|
||||||
@mock.patch("aprsd.logging.log.setup_logging")
|
@mock.patch("aprsd.log.log.setup_logging")
|
||||||
def test_no_command(self, mock_logging):
|
def test_no_command(self, mock_logging):
|
||||||
"""Make sure we get an error if there is no command."""
|
"""Make sure we get an error if there is no command."""
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ class TestSendMessageCommand(unittest.TestCase):
|
|||||||
CONF.admin.user = "admin"
|
CONF.admin.user = "admin"
|
||||||
CONF.admin.password = "password"
|
CONF.admin.password = "password"
|
||||||
|
|
||||||
@mock.patch("aprsd.logging.log.setup_logging")
|
@mock.patch("aprsd.log.log.setup_logging")
|
||||||
def test_init_flask(self, mock_logging):
|
def test_init_flask(self, mock_logging):
|
||||||
"""Make sure we get an error if there is no login and config."""
|
"""Make sure we get an error if there is no login and config."""
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user