diff --git a/.gitignore b/.gitignore
index e6ff992..4a314cd 100644
--- a/.gitignore
+++ b/.gitignore
@@ -12,6 +12,7 @@ __pycache__/
 
 # Distribution / packaging
 .Python
+.env
 env/
 env3/
 venv/
@@ -25,6 +26,7 @@ lib/
 dist/
 lib64/
 parts/
+.pytest_cache/
 sdist/
 var/
 *.egg-info/
diff --git a/sap/cf_logging/formatters/json_formatter.py b/sap/cf_logging/formatters/json_formatter.py
index 9df5474..1e941d0 100644
--- a/sap/cf_logging/formatters/json_formatter.py
+++ b/sap/cf_logging/formatters/json_formatter.py
@@ -2,22 +2,26 @@
 import json
 import logging
 import sys
+from sap.cf_logging.record.simple_log_record import SimpleLogRecord
+
+def _default_serializer(obj):
+    return str(obj)
 
 if sys.version_info[0] == 3:
     def _encode(obj):
-        return json.dumps(obj)
+        return json.dumps(obj, default=_default_serializer)
 else:
     def _encode(obj):
-        return unicode(json.dumps(obj))  # pylint: disable=undefined-variable
+        return unicode(json.dumps(obj, default=_default_serializer))  # pylint: disable=undefined-variable
 
 
 class JsonFormatter(logging.Formatter):
     """
-    Formatter for non-web application log
+    Format application log in JSON format
     """
 
     def format(self, record):
-        """ Format the log record into a JSON object """
-        if hasattr(record, 'format'):
+        """ Format the known log records in JSON format """
+        if isinstance(record, SimpleLogRecord):
             return _encode(record.format())
-        return _encode(record.__dict__)
+        return super(JsonFormatter, self).format(record)

Problem with object logging
Hello,

we run into trouble using this package in combination with the pika package (http://pika.readthedocs.io/en/0.10.0/). After initialization of the logger using cf_logging.init() the pika packages produces exceptions while trying to perform the following log operation: 

LOGGER.info('Closing channel (%s): %r on %s',
                    reply_code, reply_text, self)

Here 'reply_code' is an int, 'reply_text' a string and 'self' is the channel object which has a working __repr__ method. 

Best 
Jan
diff --git a/tests/unit/formatters/test_json_formatter.py b/tests/unit/formatters/test_json_formatter.py
new file mode 100644
index 0000000..70ffe60
--- /dev/null
+++ b/tests/unit/formatters/test_json_formatter.py
@@ -0,0 +1,24 @@
+""" Tests json log formatting """
+import json
+import logging
+from sap.cf_logging.record.simple_log_record import SimpleLogRecord
+from sap.cf_logging.formatters.json_formatter import JsonFormatter
+
+lvl, fn, lno, func, exc_info = logging.INFO, "(unknown file)", 0, "(unknown function)", None
+formatter = JsonFormatter()
+
+
+def test_unknown_records_format():
+    """ test unknown log records will be delegated to logging.Formatter """
+    log_record = logging.LogRecord('name', lvl, fn, lno, 'msg', [], exc_info)
+    assert formatter.format(log_record) == 'msg'
+
+
+def test_non_json_serializable():
+    """ test json formatter handles non JSON serializable object """
+    class MyClass(object): pass
+    extra = { 'cls': MyClass() } 
+    log_record = SimpleLogRecord(extra, None, 'name', lvl, fn, lno, 'msg', [], exc_info)
+    record_object = json.loads(formatter.format(log_record))
+    assert record_object.get('cls') is not None
+    assert 'MyClass' in record_object.get('cls')

pip install -e .[dev]
parse_log_pytest
requirements.txt
pytest pytest-cov pytest-mock pytest-asyncio Flask sanic
3.6
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
aiofiles==0.8.0
attrs==22.2.0
certifi==2021.5.30
click==8.0.4
contextvars==2.4
coverage==6.2
dataclasses==0.8
Flask==2.0.3
h11==0.9.0
httpcore==0.11.1
httptools==0.6.0
httpx==0.15.4
idna==3.10
immutables==0.19
importlib-metadata==4.8.3
iniconfig==1.1.1
itsdangerous==2.0.1
Jinja2==3.0.3
MarkupSafe==2.0.1
multidict==5.2.0
packaging==21.3
pluggy==1.0.0
py==1.11.0
pyparsing==3.1.4
pytest==7.0.1
pytest-asyncio==0.16.0
pytest-cov==4.0.0
pytest-mock==3.6.1
rfc3986==1.5.0
sanic==20.12.7
-e git+https://github.com/SAP/cf-python-logging-support.git@396ba738098024745205cbff22b2646a5337d1d1#egg=sap_cf_logging
sniffio==1.2.0
tomli==1.2.3
typing_extensions==4.1.1
ujson==4.3.0
uvloop==0.14.0
websockets==9.1
Werkzeug==2.0.3
zipp==3.6.0

name: cf-python-logging-support
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - certifi=2021.5.30=py36h06a4308_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.3=he6710b0_2
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=1.1.1w=h7f8727e_0
  - pip=21.2.2=py36h06a4308_0
  - python=3.6.13=h12debd9_1
  - readline=8.2=h5eee18b_0
  - setuptools=58.0.4=py36h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - wheel=0.37.1=pyhd3eb1b0_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - aiofiles==0.8.0
      - attrs==22.2.0
      - click==8.0.4
      - contextvars==2.4
      - coverage==6.2
      - dataclasses==0.8
      - flask==2.0.3
      - h11==0.9.0
      - httpcore==0.11.1
      - httptools==0.6.0
      - httpx==0.15.4
      - idna==3.10
      - immutables==0.19
      - importlib-metadata==4.8.3
      - iniconfig==1.1.1
      - itsdangerous==2.0.1
      - jinja2==3.0.3
      - markupsafe==2.0.1
      - multidict==5.2.0
      - packaging==21.3
      - pluggy==1.0.0
      - py==1.11.0
      - pyparsing==3.1.4
      - pytest==7.0.1
      - pytest-asyncio==0.16.0
      - pytest-cov==4.0.0
      - pytest-mock==3.6.1
      - rfc3986==1.5.0
      - sanic==20.12.7
      - sniffio==1.2.0
      - tomli==1.2.3
      - typing-extensions==4.1.1
      - ujson==4.3.0
      - uvloop==0.14.0
      - websockets==9.1
      - werkzeug==2.0.3
      - zipp==3.6.0
prefix: /opt/conda/envs/cf-python-logging-support

tests/unit/formatters/test_json_formatter.py::test_unknown_records_format tests/unit/formatters/test_json_formatter.py::test_non_json_serializable
.gitignore sap/cf_logging/formatters/json_formatter.py
.gitignore sap/cf_logging/formatters/json_formatter.py