Skip to content

Commit

Permalink
fixes tintoy#76
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrmaslanka committed Dec 20, 2024
1 parent 762991a commit 67e96cd
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 199 deletions.
10 changes: 10 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@
# The master toctree document.
master_doc = 'index'

autodoc_default_options = {
'members': True,
}
autodoc_default_flags = [
'show-inheritance'
]
autodoc_typehints = "description"
autoclass_content = 'both'


# General information about the project.
project = u'SeqLog'
copyright = u"2016, Adam Friedman"
Expand Down
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Contents:

readme
installation
migration
usage
usage-gunicorn
Modules <api/modules>
Expand Down
22 changes: 22 additions & 0 deletions docs/migration.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
===============================
Migration guide from 0.4 to 0.5
===============================

First of all, the official way to configure Seq is via

.. autofunction:: seqlog.configure_from_dict

Alternatively you can call

.. autofunction:: seqlog.configure_from_file


.. warning:: DO NOT call :code:`logging.config.fromDict`

Then, FeatureFlags were completely obliterated and moved to SeqLogHandler's constructor.

Then, the SeqLogHandler accepts way more arguments that you can define in this dict:

.. autoclass:: seqlog.structured_logging.SeqLogHandler
:members:

31 changes: 4 additions & 27 deletions docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ First, create your configuration file (e.g. ``/foo/bar/my_config.yml``):
# Configure logging from scratch.
disable_existing_loggers: True
override_root_logger: True
use_structured_logger: True
# Configure the root logger to use Seq
root:
Expand Down Expand Up @@ -98,7 +100,7 @@ First, create your configuration file (e.g. ``/foo/bar/my_config.yml``):
seq:
style: '{'
Then, call ``seqlog.configure_from_file()``:
Then, call :func:`seqlog.configure_from_file`:

.. code-block:: python
Expand All @@ -115,11 +117,9 @@ Then, call ``seqlog.configure_from_file()``:
Configuring logging from a dictionary
-------------------------------------

.. deprecated:: 0.5.0
Use logging.config.dictConfig() directly

Seqlog can also use a dictionary to describe the desired logging configuration.
This dictionary has the schema specified in Python's `logging.config <https://docs.python.org/3/library/logging.config.html#logging-config-dictschema>`_ module.
With some extra options described in :func:`seqlog.configure_from_dict`.

.. code-block:: python
Expand All @@ -137,29 +137,6 @@ This dictionary has the schema specified in Python's `logging.config <https://do
another_logger = logging.getLogger('another_logger')
another_logger.info('This is another logger.')
Note that you can pass flags that were previously given to :func:`seqlog.configure_from_dict` directly in the dictionary, eg.

.. autofunction:: seqlog.configure_from_dict

.. code-block:: python
a['handlers']['console'] = {
'class': 'seqlog.structured_logging.ConsoleStructuredLogHandler',
'formatter': 'standard'
'override_root_logger': True
'use_structured_logging': True,
'use_clef': True
}
logging.config.dictConfig(a)
Basically all of the arguments in

.. autoclass:: seqlog.structured_logging.BaseStructuredLogHandler

can be put there.

Note that only first arguments that were previously passed globally will be set. Argument configured once in one logger
won't pass to another.
Batching and auto-flush
-----------------------
Expand Down
35 changes: 16 additions & 19 deletions seqlog/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import yaml

from seqlog.feature_flags import FeatureFlag, configure_feature
from seqlog.structured_logging import StructuredLogger, StructuredRootLogger, _override_root_logger
from seqlog.structured_logging import SeqLogHandler, ConsoleStructuredLogHandler
from seqlog.structured_logging import get_global_log_properties as _get_global_log_properties
Expand All @@ -23,32 +22,34 @@

def configure_from_file(file_name):
"""
Configure Seq logging using YAML-format configuration file.
Configure Seq logging using YAML-format configuration file. Essentially loads the YAML, and invokes
:func:`configure_from_dict`.
Uses `logging.config.dictConfig()`.
"""

with open(file_name) as config_file:
config = yaml.load(config_file, Loader=yaml.SafeLoader)

logging.config.dictConfig(config)
configure_from_dict(config)


def configure_from_dict(config):
"""
Configure Seq logging using a dictionary.
Uses `logging.config.dictConfig()`.
Configure Seq logging using a dictionary. Use it instead of logging.config.dictConfig().
.. deprecated: 0.5.0
Use logging.config.dictConfig() directly.
Extra parameters you can specify (as dictionary keys).
Note that if you provide None to any of the default arguments, it just won't get changed (ie. it will stay the same).
* `use_structured_logger` - this will configure Python logging environment to use a StructuredLogger, ie. one that
understands keyword arguments
* `override_root_logger` - overrides root logger with a StructuredLogger
:param config: A dict containing the configuration.
:type config: dict
The rest will be passed onto logging.config.dictConfig()
"""
warnings.warn('This is deprecated, use logging.config.dictConfig() directly', DeprecationWarning)
if config.pop('use_structured_logger', False):
logging.setLoggerClass(StructuredLogger)
if config.pop('override_root_logger', False):
_override_root_logger()
logging.config.dictConfig(config)


Expand Down Expand Up @@ -86,19 +87,15 @@ def log_to_seq(server_url, api_key=None, level=logging.WARNING,
:return: The `SeqLogHandler` that sends events to Seq. Can be used to forcibly flush records to Seq.
:rtype: SeqLogHandler
"""

configure_feature(FeatureFlag.EXTRA_PROPERTIES, support_extra_properties)
configure_feature(FeatureFlag.STACK_INFO, support_stack_info)
configure_feature(FeatureFlag.IGNORE_SEQ_SUBMISSION_ERRORS, ignore_seq_submission_errors)
configure_feature(FeatureFlag.USE_CLEF, use_clef)

logging.setLoggerClass(StructuredLogger)

if override_root_logger:
_override_root_logger()

log_handlers = [
SeqLogHandler(server_url, api_key, batch_size, auto_flush_timeout, json_encoder_class)
SeqLogHandler(server_url, api_key, batch_size, auto_flush_timeout, json_encoder_class,
support_extra_properties=support_extra_properties, support_stack_info=support_stack_info,
use_clef=use_clef, ignore_seq_submission_errors=ignore_seq_submission_errors)
]

if additional_handlers:
Expand Down
77 changes: 0 additions & 77 deletions seqlog/feature_flags.py

This file was deleted.

Loading

0 comments on commit 67e96cd

Please sign in to comment.