help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How can function know its own name?


From: Emanuel Berg
Subject: Re: How can function know its own name?
Date: Sat, 25 Jun 2022 23:37:09 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)

Jean Louis wrote:

> I would like to invoke logging for specific functions
> automatically, without specifying what to log, and my
> function should know which function invoked it.
>
> For example
>
> (defun my-log (&optional function-name)
>   (log-to-database function-name))
>
> (defun logged-function ()
>   (my-log (find-function-name)) ;; I would like at this point
> to recognize that it was invoked from within logged-function?
>   (ignore))
>
> Would this be possible somehow?

You can do a function called for example 'log-this-function'.

You send the function you wish to log to that function, it
then does a `advice-add' :before (or :after?) the function
that's supposed to be logged and the advice function can then
have the function's name with `symbol-name' since that's
available in 'log-this-function' ...

-- 
underground experts united
https://dataswamp.org/~incal




reply via email to

[Prev in Thread] Current Thread [Next in Thread]