From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on starla X-Spam-Level: X-Spam-Status: No, score=-1.1 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 Received: from nue.mailmanlists.eu (nue.mailmanlists.eu [94.130.110.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 58FEA1F4C4 for ; Thu, 7 Nov 2024 01:27:15 +0000 (UTC) Authentication-Results: dcvr.yhbt.net; dkim=pass (1024-bit key; unprotected) header.d=ml.ruby-lang.org header.i=@ml.ruby-lang.org header.a=rsa-sha256 header.s=mail header.b=p+Vwtt2B; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ruby-lang.org header.i=@ruby-lang.org header.a=rsa-sha256 header.s=s1 header.b=ggQELSEq; dkim-atps=neutral DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ml.ruby-lang.org; s=mail; t=1730942803; bh=fv5aNXhyWBh8eYK1lf4MvjZgupWL5uu6SuYEDiUJGq8=; h=Date:References:To:Reply-To:Subject:List-Id:List-Archive: List-Help:List-Owner:List-Post:List-Subscribe:List-Unsubscribe: From:Cc:From; b=p+Vwtt2Bb+SpDKOzyxORXyTv+i+Q6DkF9VhRxbDPPTP8Ea2vnNb/uAMhCFF3kR78Y zSctFg8ZRKSMeFgasanb2GOu9v5vzHx04oVBgofqkN3HbPI3r2fRPwltt5dWidXO0O mAAuxMNyPGhq0pCShQM1QGqA7mZ7WeQdiNyhaed4= Received: from nue.mailmanlists.eu (localhost [IPv6:::1]) by nue.mailmanlists.eu (Postfix) with ESMTP id 0FA5944B01 for ; Thu, 7 Nov 2024 01:26:43 +0000 (UTC) Authentication-Results: nue.mailmanlists.eu; dkim=pass (2048-bit key; unprotected) header.d=ruby-lang.org header.i=@ruby-lang.org header.a=rsa-sha256 header.s=s1 header.b=ggQELSEq; dkim-atps=neutral Received: from s.wfbtzhsw.outbound-mail.sendgrid.net (s.wfbtzhsw.outbound-mail.sendgrid.net [159.183.224.105]) by nue.mailmanlists.eu (Postfix) with ESMTPS id 59622441F9 for ; Thu, 7 Nov 2024 01:26:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ruby-lang.org; h=from:references:subject:mime-version:content-type: content-transfer-encoding:list-id:to:cc:content-type:from:subject:to; s=s1; bh=8LeypEKIrSG3T7qPaXpuFLhq4cUVEDz9i+AeJwAyIrQ=; b=ggQELSEqy2rdgmeqrQE5fr9UvDpoKXdisJjxGBRZbkBsQlfZBWzKnShZI2R9LXmuDRPk rSe7SC1V34tEyp8NIYCEUem9Qg16qvmkTk6rFgjzMX18p1JxSINn/P5ZsUUcHnJjvNcOoO vasbnLzmTYdc9mec6rawznOKyl+gNJ/iPYm4WCVjnOgDO5BwRVC80liomdrVQgURyzcYgL lkd1snquG1oqFK29gZAlnSm2qNBACG8F6qKH7Y1L+udcSc+Xl2bHdjj/Ifs9AsfLqDgIXC JKWA0yMQX1CU41Cnd0qz67CVaTlVy4RWjrwSEENjaAGWhFH9/+5HITzrUkJdvgJg== Received: by recvd-7cc7f7d978-dvzlp with SMTP id recvd-7cc7f7d978-dvzlp-1-672C1747-12 2024-11-07 01:26:31.423567955 +0000 UTC m=+4779034.127910367 Received: from herokuapp.com (unknown) by geopod-ismtpd-23 (SG) with ESMTP id ZOQuyKA9TN-5NcoTtri2QA for ; Thu, 07 Nov 2024 01:26:31.350 +0000 (UTC) Date: Thu, 07 Nov 2024 01:26:31 +0000 (UTC) Message-ID: References: Mime-Version: 1.0 X-Redmine-Project: ruby-master X-Redmine-Issue-Tracker: Feature X-Redmine-Issue-Id: 20864 X-Redmine-Issue-Author: ioquatix X-Redmine-Issue-Priority: Normal X-Redmine-Sender: ioquatix X-Mailer: Redmine X-Redmine-Host: bugs.ruby-lang.org X-Redmine-Site: Ruby Issue Tracking System X-Auto-Response-Suppress: All Auto-Submitted: auto-generated X-Redmine-MailingListIntegration-Message-Ids: 96454 X-SG-EID: =?us-ascii?Q?u001=2E3QFJPY5gaRwyNXkncYONHM3OeFnb=2FgeOrLDgg3PYIKrq5rvk81iAipQ1q?= =?us-ascii?Q?cdmuT9o5PIWGjXtTDstodNmslT=2F6xfCuIofWR2K?= =?us-ascii?Q?w8msDgVaVLzS9q+pnATr44Vx0oUaL4cB4QbzVT3?= =?us-ascii?Q?7wqx=2Fuxm9ApSW67afWQgzno1ajGaoqaTkOBzvCv?= =?us-ascii?Q?HXhYdcfNJkw=2FmOgk8zED5HozgeFy0=2F22b0nMk50?= =?us-ascii?Q?3X9VBqKwpwtSn4Qlh3f9wxiAHvtxhEFdXQdtZK9?= =?us-ascii?Q?kbVS1FRQ+HkNiP5RcN=2FHBuuQkQ=3D=3D?= To: ruby-core@ml.ruby-lang.org X-Entity-ID: u001.I8uzylDtAfgbeCOeLBYDww== Message-ID-Hash: YUMTFL6NJSHQIDMXBZCHLGSP7JM52EZX X-Message-ID-Hash: YUMTFL6NJSHQIDMXBZCHLGSP7JM52EZX X-MailFrom: bounces+313651-b711-ruby-core=ml.ruby-lang.org@em5188.ruby-lang.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.9 Precedence: list Reply-To: Ruby developers Subject: [ruby-core:119788] [Ruby master Feature#20864] Allow `Kernel#warn` to accept `**options` and pass these to `Warning.warn`. List-Id: Ruby developers Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: "ioquatix (Samuel Williams) via ruby-core" Cc: "ioquatix (Samuel Williams)" Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Issue #20864 has been updated by ioquatix (Samuel Williams). I checked C interface in `error.h` and we end up having a lot of variants: - `rb_warn` - `rb_warning` - `rb_category_warn` - `rb_compile_warn` - `rb_category_compile_warn` etc. One idea is this: ``` struct rb_warning_arguments { rb_warning_category_t category; VALUE extra; // others }; void rb_warning(struct rb_warning_arguments, const char *fmt, ...); ``` For things like: ``` void rb_category_compile_warn(rb_warning_category_t cat, const char *file, int line, const char *fmt, ...); ``` I imagine that `cat`, `file` and `line` are all useful structured data. ---------------------------------------- Feature #20864: Allow `Kernel#warn` to accept `**options` and pass these to `Warning.warn`. https://bugs.ruby-lang.org/issues/20864#change-110465 * Author: ioquatix (Samuel Williams) * Status: Open ---------------------------------------- ## Background Structured logging is a practice that organizes log data in a consistent, easily parseable format. Unlike traditional unstructured logs, which often consist of plain text entries, structured logs format information in key-value pairs or structured data formats such as JSON. This allows for better automation, searchability, and analysis of log data. In Ruby, `Kernel#warn` is extremely useful, especially because there is a mechanism for loggers to redirect warnings using the `Warning` module. However, it is difficult to generate structured logs with `Kernel#warn` as all the positional arguments are converted to a single string, and arbitrary keyword options are rejected. As a consequence, code like this is not possible: ```ruby begin ... rescue => error warn "Something went wrong!", exception: error end ``` It is very desirable to have a standard interface in Ruby for emitting structured warnings. ## Proposal I'd like to extend the current implementation to allow all options to be forwarded to `Warning.warn`. This would allow us to add more details to warnings and emit structured logs using `Warning.warn`. A simple example of the proposed interface: ```ruby module Kernel def warn(*arguments, uplevel: ..., **options) # Existing processing of arguments -> message ::Warning.warn(message, **options) end end ``` Current behaviour rejects any unknown options: ``` warn("Oops", exception: error) # => :50:in `warn': unknown keyword: :exception (ArgumentError) ``` I don't have an opinion about the implementation, but I wanted to get feedback on the interface. Regarding the default behaviour, I propose no changes. -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/