I'm creating a log function that will log my errors in a file.
I thought it will contain which class and method the error occurred in.
Is there a way of logging in which class and method the error occurred in so I don't have to type it manually each time?
The simplest way is to call the getClass() method that returns the class's name or interface represented by an object that is not an array. We can also use getSimpleName() or getCanonicalName() , which returns the simple name (as in source code) and canonical name of the underlying class, respectively.
The first and easiest method to get a class name in python is by using __class__ property which basically refers to the class of the object we wish to retrieve. Here we combine the property with __name__ property to identify the class name of the object or instance.
Go to SE16, enter table name SEOCOMPO and enter your method name for the field CMPNAME and execute. You will get all the classes that has this method. Remember, methods are not independent of its class. So the same method name can be implemented in different classes differently.
The current method name that contains the execution point that is represented by the current stack trace element is provided by the java. lang. StackTraceElement. getMethodName() method.
I'm not big on PHP but I believe it has "magic constants" similar to C/C++. Take a look here: This seems to indicate you could use
__LINE__, __FILE__, __FUNCTION__, __CLASS__, and __METHOD__
In the event your in a parent / base class, __CLASS__
will return the parent / base class name which is not desired. In that event you can use get_class()
:
get_class($this)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With