Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

How do I get named loggers with different sets of appenders? #200

Answered by reidmorrison
xrl asked this question in Q&A
Discussion options

Environment

Provide at least:

  • Ruby 2.3.1
  • Semantic Logger Version: master
  • Application/framework names and versions: rails 4.2

Expected Behavior

I would like to use a named semantic logger, created by SAML_LOGGER = SemanticLogger['SAML'] and I would like to then add appenders to this SAML logger so it writes to Elasticseach with the proper type field (that's an option on the Elasticsearch appender). I'd like to then bring in semantic_logger_rails and configure its appender to use the standard log type. As the code stands today, I don't think I can reuse appenders in the same process as they are all registered with the singleton SemanticLogger@appenders concurrent array.

I can tell this will complicate the concurrency model, as there is a single background thread which processes all the logs and invokes the appenders.

SAML_LOGGER = SemanticLogger['SAML']
SAML_LOGGER.add_appender(:elasticsearch, type: 'saml', ...)
SemanticLogger.add_appender(:elasticserach, type: 'log', ...)
Rails.log.info("hi") # should create a 'log' type for Elasticsearch
SAML_LOGGER.info("hello") # should create a 'saml' type for Elasticsearch

Any possible workarounds without tearing through this library?

You must be logged in to vote

Correct, by design all log entries go to all appenders.
You can however add a filter to an appender so that it only logs messages from specific classes.

Replies: 1 comment

Comment options

Correct, by design all log entries go to all appenders.
You can however add a filter to an appender so that it only logs messages from specific classes.

You must be logged in to vote
0 replies
Answer selected by reidmorrison
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #89 on January 17, 2022 21:01.

AltStyle によって変換されたページ (->オリジナル) /