Skip to content

make scoped logger work with logger objects with non-int level#486

Open
HoneyryderChuck wants to merge 1 commit into
temporalio:mainfrom
persona-id:scoped-logger-non-integer-level
Open

make scoped logger work with logger objects with non-int level#486
HoneyryderChuck wants to merge 1 commit into
temporalio:mainfrom
persona-id:scoped-logger-non-integer-level

Conversation

@HoneyryderChuck

Copy link
Copy Markdown

What was changed

This patch fixes scoped loggers by allowing a escape hatch for logger objects with non-integer levels; just call #upcase (which both strings and symbols support) and pass it to Logger::Severity.const_get.

Why?

Logger#level returns an integer, however many other logger libraries in ruby land don't do that, most notably semantic_logger, which is nowadays recommended by rails for structured logging; SemanticLogger::Logger objects return #level as a symbol (ex: :info).

Checklist

  1. Closes [Bug] Does not support semantic_logger #472

  2. How was this tested:

require "semantic_logger"
require "temporalio"

logger = SemanticLogger["MyApp"]
scoped_logger = ScopedLogger.new(logger)
scoped_logger.level #=> 1, 2 ,3....

3. Any docs updates needed?

Don't think so, temporalio does not document support for logger libs.

@HoneyryderChuck
HoneyryderChuck requested a review from a team as a code owner July 13, 2026 18:38
@CLAassistant

CLAassistant commented Jul 13, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@HoneyryderChuck
HoneyryderChuck force-pushed the scoped-logger-non-integer-level branch 2 times, most recently from d587d28 to df7793c Compare July 14, 2026 22:04

@chris-olszewski chris-olszewski left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add some testing that exersices against Semantic Logger


return Logger::UNKNOWN unless lvl.respond_to?(:upcase)

Logger::Severity.const_get(lvl.upcase, false) || Logger::UNKNOWN

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logger::Severity doesn't have TRACE which seems to be valid for semantic logger which would result in this throwing.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you're right, fixed.

`Logger#level` returns an integer, however many other logger libraries
in ruby land don't do that, most notably semantic_logger, which is
nowadays recommended by rails for structured logging;
`SemanticLogger::Logger` objects return `#level` as a symbol (ex:
`:info`).

This patch fixes it by allowing a escape hatch for non-integer levels;
just call `#upcase` (which both strings and symbols support) and pass it
to `Logger::Severity.const_get`.
@HoneyryderChuck
HoneyryderChuck force-pushed the scoped-logger-non-integer-level branch from df7793c to 64da642 Compare July 15, 2026 16:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Does not support semantic_logger

3 participants