DocumentationDiscussions
DocumentationDiscussions

Discussions

Ask a Question
Back to All

Using Seq for Python with Flask

I have the code below to configure the project to log to seq. Which was copy and pasted from the documentation.

'''
import json
import logging

from flask import Flask
from config import Config
import seqlog

app = Flask(name)
app.config.from_object(Config)

seqlog.log_to_seq(
server_url="http://***:5341/",
api_key="***",
level=logging.DEBUG,
batch_size=5,
auto_flush_timeout=2, # seconds
override_root_logger=True,
json_encoder_class=json.encoder.JSONEncoder
)

import views
'''

When the app starts i get the following error:
'''
FLASK_APP = app.py
FLASK_ENV = development
FLASK_DEBUG = 0
In folder /Users/kelvinmacartney/PycharmProjects/comp-2011-cwk-2
/Users/kelvinmacartney/PycharmProjects/comp-2011-cwk-2/venv/bin/python -m flask run

  • Serving Flask app "app.py"
  • Environment: development
  • Debug mode: off
    /usr/local/Cellar/python/3.7.1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/sqlalchemy/ext/declarative/base.py:325: SAWarning: Attribute 'username' on class <class 'models.User'> appears to be a non-schema 'sqlalchemy.sql.column()' object; this won't be part of the declarative mapping
    (key, cls))
    /usr/local/Cellar/python/3.7.1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/sqlalchemy/ext/declarative/base.py:325: SAWarning: Attribute 'email' on class <class 'models.User'> appears to be a non-schema 'sqlalchemy.sql.column()' object; this won't be part of the declarative mapping
    (key, cls))
    Exception in thread Thread-1:
    Traceback (most recent call last):
    File "/usr/local/Cellar/python/3.7.1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/threading.py", line 917, in _bootstrap_inner
    self.run()
    File "/usr/local/Cellar/python/3.7.1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/threading.py", line 1158, in run
    self.function(*self.args, self.kwargs)
    File "/usr/local/Cellar/python/3.7.1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/seqlog/consumer.py", line 67, in flush
    self.callback(current_batch)
    File "/usr/local/Cellar/python/3.7.1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/seqlog/structured_logging.py", line 366, in publish_log_batch
    request_body_json = json.dumps(request_body, cls=self.json_encoder_class)
    File "/usr/local/Cellar/python/3.7.1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/init.py", line 238, in dumps
    kw).encode(obj)
    File "/usr/local/Cellar/python/3.7.1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
    File "/usr/local/Cellar/python/3.7.1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
    File "/usr/local/Cellar/python/3.7.1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/encoder.py", line 179, in default
    raise TypeError(f'Object of type {o.class.name} '
    TypeError: Object of type ColumnSet is not JSON serializable
    '''

The site runs fine, but when i try to log i get an exception. Is there something i'm missing?