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 v3 6/7] logging: Make procedure name available to the log formatter. Date: Thu, 8 Feb 2024 23:50:47 -0500 Message-ID: <20240209045150.17210-7-maxim.cournoyer@gmail.com> References: <20240206034201.28494-1-maxim.cournoyer@gmail.com> <20240209045150.17210-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="18641"; 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 Fri Feb 09 05:52:48 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 1rYIsa-0004jH-9w for guile-devel@m.gmane-mx.org; Fri, 09 Feb 2024 05:52:48 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rYIrw-0006xl-MQ; Thu, 08 Feb 2024 23:52:08 -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 1rYIru-0006sz-Tm for guile-devel@gnu.org; Thu, 08 Feb 2024 23:52:06 -0500 Original-Received: from mail-qk1-x729.google.com ([2607:f8b0:4864:20::729]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rYIrt-0000QU-E1 for guile-devel@gnu.org; Thu, 08 Feb 2024 23:52:06 -0500 Original-Received: by mail-qk1-x729.google.com with SMTP id af79cd13be357-783e22a16d4so135551585a.0 for ; Thu, 08 Feb 2024 20:52:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707454324; x=1708059124; 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=pRTJW2N4Mph3PGGVoJniA/sEBBb/fyT9eULKygot+6s=; b=kSzAtGAjKXjcxKNO5+ZBZ5gILK80v29W4sZ/T8M+c3P+0yzmhX+k30XYk67U7O+ySA aKFobh/ECeeHjxouuM7o7fHkEM1jD0UnUP9ySPLMszxdvUCUmkmuIT2LDtxiceKDsGVz PSZYx41JhtsAkOul2PZDU8U5boUCvHjvE4mptoBmp3KjF6MjunB2AJptGabL1NPWEzRn gYDs+WfCMQlSZCxRc3cPp8aQCoFCiebtcrbUKJUe4AefqDXfOYOpYeQRha31z7z7jVTk 2CTZGdFAcASxpLz62MgzSvY5/jxmyG9rZdJUL0C1u+VNhqdTBtoVSe7ZuQ+hGzmBRauS nxhg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707454324; x=1708059124; 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=pRTJW2N4Mph3PGGVoJniA/sEBBb/fyT9eULKygot+6s=; b=FaCcy5paINGHqHUPzFE7K5E0VATOQ0SxcHjk0eS7gyhL6GQW5MRVoBMSGP7MUfxPVT cSeVNM6zmcIFBN7E8nsn9GqBxIQRIRzRmzY+T1zuXLNMPiLCv2z7alXhhvCQYNuSFwl9 VfDpJ5bAvyEexW8FR8UXiVc3tysG03PXHUcRfBcbTps8pdksOfJgU5pWxynlkMa6VvBF zzLVkOipb4izn7Lf+hCAngodk/UEnWFcXg9ZQ/PNC3Y46bgHV47zEWJNCW60HLn9krAH M4I+bHerVMyAoto/Cg7QizgX5Sr6HTCp+uGRlOqdsTpO/bIs7OO6+lKJqW4z6skB+lZC nzHA== X-Gm-Message-State: AOJu0YzctpZFIrULAmiYr0v1CtJGlnEr6i0u4e86yWIyH9ghYw+vaRZM /4L7s/LUK9KttOgjjdZpHTmI6esA7tXadb5ff+9ZxlKFUk0YYHt9ZdjM8PiO X-Google-Smtp-Source: AGHT+IHv0bbEovX9vpzxMMEnkQ4Ozz9iK8dV/DVuPsZsuEnVsRRsrt+pk552cGsSPVm8Q8OtVvc1MA== X-Received: by 2002:a05:620a:222a:b0:785:6884:f333 with SMTP id n10-20020a05620a222a00b007856884f333mr711206qkh.10.1707454324173; Thu, 08 Feb 2024 20:52:04 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCXnXd1NPAx4JaiPtw12S4Fix0agKs7+bZMcKts/iIEBdguqs0RXgekeAj/JCo1J52H8zyShMyV/bgzBTuEORd5BGA9IGdNhbdlJ Original-Received: from localhost.localdomain (dsl-10-135-252.b2b2c.ca. [72.10.135.252]) by smtp.gmail.com with ESMTPSA id p3-20020a05620a112300b00785a2d275f0sm426970qkk.41.2024.02.08.20.52.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 20:52:03 -0800 (PST) X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240209045150.17210-1-maxim.cournoyer@gmail.com> Received-SPF: pass client-ip=2607:f8b0:4864:20::729; envelope-from=maxim.cournoyer@gmail.com; helo=mail-qk1-x729.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:22313 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 05850a9..7085d26 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 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 @@ -283,21 +284,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))) @@ -352,10 +357,11 @@ override this behavior.") ;; This can be overridden by log handlers if this default behaviour ;; is not desired.. (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