From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Maxim Cournoyer Newsgroups: gmane.lisp.guile.devel Subject: [Guile-Lib PATCH v4 6/7] logging: Make procedure name available to the log formatter. Date: Sun, 25 Feb 2024 09:19:12 -0500 Message-ID: <20240225141935.8420-7-maxim.cournoyer@gmail.com> References: <20240225141935.8420-1-maxim.cournoyer@gmail.com> Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="16879"; mail-complaints-to="usenet@ciao.gmane.io" Cc: David Pirotte , Maxim Cournoyer To: guile-devel@gnu.org Original-X-From: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Sun Feb 25 15:20:40 2024 Return-path: Envelope-to: guile-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1reFMt-0004Fa-Su for guile-devel@m.gmane-mx.org; Sun, 25 Feb 2024 15:20:40 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1reFMB-0002Ny-C6; Sun, 25 Feb 2024 09:19:55 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1reFMA-0002Nc-7H for guile-devel@gnu.org; Sun, 25 Feb 2024 09:19:54 -0500 Original-Received: from mail-oi1-x22d.google.com ([2607:f8b0:4864:20::22d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1reFM8-0004WO-IT for guile-devel@gnu.org; Sun, 25 Feb 2024 09:19:53 -0500 Original-Received: by mail-oi1-x22d.google.com with SMTP id 5614622812f47-3c02adddb8eso1924094b6e.0 for ; Sun, 25 Feb 2024 06:19:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708870791; x=1709475591; darn=gnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=6Mkq0zHrx1dNUV210+iF4jDah4LOTWxoT88NU+X2gXY=; b=btm9MJu4TLosqHXL0syjkE7oljlToFqhXAH3fpEIHGmsn59GN4rGU67i0vV2mvwbXl EW8s3+3X0eTndJflbLf5yHk4B/QRpzGnWYPaU8uXeVSoEZcyJ2ryyBCydM0CN5P3V3jp OaWNlGGRjmFDj+7OmAXiFhzrrULiUOKeyiJG4SzU9GnbvxHqYB0isg2mSHvhUNQusMbU GFqnHwMjmnY8xlnw1PciXHqTwD+vAU8Wy6HdX61FKVnbsB6Q6Py5pKruSocw56MaT6vN I7dmOjTzX+VAQC/hbxkcR70KznbanzMeqNNoWDoYRgPFC1cqXknCZO6XVF/qjfgy2cd1 CBbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708870791; x=1709475591; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6Mkq0zHrx1dNUV210+iF4jDah4LOTWxoT88NU+X2gXY=; b=Nkg4f60dqv0wOPeHnc1VPLlmHBCdcqz87STTGS2uG23c31WScL8L44YuLEZtU9rkBb VhgQba0hHekvCSKtHoZQ/afkQcHAvfh95/G1AkuzbLy3Wb5XcUTw59FP6lGSoeKkKq0+ N5MGO6vcDBTuK7rotAXP5KocEyZh2OUy5UsfSJpCoTdYpJ8Pon8TZmviczIYNFpT0AJC k8KwZbkkBTf1JcyzYesah8OO18e8jI/9Tpqkzcg4auiwHHPkjHXyOu4T9/sEgZqfnN4V q3FDb0BBk8CfkKot56lGxgulewjYu0yFCCBlfrehq1BRcVZmetJJCMi+6rYsIp6wW0PN NolQ== X-Gm-Message-State: AOJu0Yx/bEr7fmh4Zic6XbQsh5tz/LXqi9h5tvE7m7Q+ZyR+KGnjCH5q V/JK9XN46JF9oYkohfimoRJPsEwqVw/JgboE/OYaiA3Dxp9RdS11Whf5+Wx3 X-Google-Smtp-Source: AGHT+IGL/zyFi7cu8cCwCxv5FgDVey+Sa/8wZJAYydrYN6tQv8brImWnZCve9kBWUqj0w3j053XACA== X-Received: by 2002:a05:6808:21a3:b0:3c1:7019:ae9b with SMTP id be35-20020a05680821a300b003c17019ae9bmr6525984oib.43.1708870789284; Sun, 25 Feb 2024 06:19:49 -0800 (PST) Original-Received: from localhost.localdomain (dsl-141-6.b2b2c.ca. [66.158.141.6]) by smtp.gmail.com with ESMTPSA id kr2-20020a0562142b8200b0068fcaa599f6sm1780591qvb.67.2024.02.25.06.19.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Feb 2024 06:19:48 -0800 (PST) X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240225141935.8420-1-maxim.cournoyer@gmail.com> Received-SPF: pass client-ip=2607:f8b0:4864:20::22d; envelope-from=maxim.cournoyer@gmail.com; helo=mail-oi1-x22d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Original-Sender: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.lisp.guile.devel:22328 Archived-At: * src/logging/logger.scm (log-helper): Retrieve procedure name and pass it to `accept-log'. (default-log-formatter): Register new proc-name keyword argument, and include it in formatted message. (accept-log): New proc-name positional argument; pass it to log-formatter. * unit-tests/guile-library.api: Regenerate. --- (no changes since v1) src/logging/logger.scm | 22 ++++++++++++++-------- unit-tests/guile-library.api | 2 +- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/logging/logger.scm b/src/logging/logger.scm index 6a5b824..b75d603 100644 --- a/src/logging/logger.scm +++ b/src/logging/logger.scm @@ -222,13 +222,14 @@ Handlers can always be added later via @code{add-handler!} calls. (define* (log-helper lgr level objs #:key source-properties) ;; the level must be enabled in the logger to proceed... (if (level-enabled? lgr level) - (let ((cur-time (current-time))) + (let ((cur-time (current-time)) + (proc-name (frame-procedure-name (stack-ref (make-stack #t) 2)))) (for-each (lambda (str) (unless (string-null? str) ;; pass the string to each log handler for lgr (for-each (lambda (handler) (accept-log handler level cur-time str - source-properties)) + source-properties proc-name)) (handlers lgr)))) ;; split the string at newlines into different log statements @@ -285,21 +286,25 @@ timestamps to log statements. ;; the default formatter makes a log statement like: ;; 2003/12/29 14:53:02 (CRITICAL): The servers are melting! (define* (default-log-formatter lvl time str - #:key source-properties + #:key source-properties proc-name #:allow-other-keys) "Default log formatting procedure. For source properties to be available, they must be manually provided to @code{log-msg} via a -suitable syntax wrapper (currently left to the user to implement)." +suitable syntax wrapper (currently left to the user to implement). +@var{proc-name}, if available, is the name of the procedure the +message was logged from." (let ((file-name (assoc-ref source-properties 'filename)) ;; Note: increment the source property zero-indexed line by 1, ;; to comply with the GNU Standards guidelines (info ;; '(standards) Errors'). (line (and=> (assoc-ref source-properties 'line) 1+)) (column (assoc-ref source-properties 'column))) - (format #f "~a ~@[~a ~]~:@(~a~): ~a~%" + (format #f "~a ~@[~a ~]~@[(~a) ~]~:@(~a~): ~a~%" (strftime "%F %H:%M:%S" (localtime time)) (and (or file-name line column) - (format #f "~@[~a:~]~@[~a:~]~@[~a:~]" file-name line column)) + (format #f "~@[~a:~]~@[~a:~]~@[~a:~]" + file-name line column)) + proc-name lvl str))) @@ -359,10 +364,11 @@ override this behavior.") (emit-log self ((log-formatter self) level time str)))) (define-method (accept-log (self ) level time str - source-properties) + source-properties proc-name) (when (level-enabled? self level) (emit-log self ((log-formatter self) level time str - #:source-properties source-properties)))) + #:source-properties source-properties + #:proc-name proc-name)))) ;; This should be overridden by all log handlers to actually ;; write out a string. diff --git a/unit-tests/guile-library.api b/unit-tests/guile-library.api index 594a1ab..e879b9d 100644 --- a/unit-tests/guile-library.api +++ b/unit-tests/guile-library.api @@ -90,7 +90,7 @@ ( class) (accept-log generic - ( )) + ( )) (add-handler! generic ( )) (close-log! generic -- 2.41.0