-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cannot name the logger object "logger" #9
Comments
Yep, that's a flaw in the documentation. I think it's left over from when I was using a different name for the top-level package/namespace, and then did a global search-and-replace without closely re-reading all the example code. You shouldn't, and maybe can't, use the same name for both a local variable and a package, though I'm not sure exactly what errors it'll cause. I'll come up with a better variable name and update the examples here. |
Okay, you know what: SLF4M has few enough users at this point that we can take a breaking change to the interface. |
My background with logging frameworks is only from python standard logging framework. I have no direct experience with log4j, but I believe there is a lot of similarity. Hopefully my python background explains my mental model and the prism through which I am seeing things. |
In python, we use the package function like
and use a logger object method like
|
Your background with these other logging packages is relevant; they all work pretty similarly, and SLF4M is explicitly modeled on them. The issue here is actually one specifically with Matlab's syntax for M-code and packages: in Matlab, package or namespace prefix names, and the prefixes for package-qualifying an identifier name in a function or class reference, effectively share a namespace with local variables, and syntactically look exactly like object or struct field references on local variables (and some other things), and they can collide, and when they do, sometimes they produce error conditions that are non-obvious. In Java, its syntax has a distinct form for package qualification, which makes package names and local variables separate namespaces, so they can't collide at all. And in Python, module imports effectively are variables within another module, so it's a single (local) namespace and you can have collisions, but they're more obvious, and Python developers will know how to work around them, because that is a normal and common way for things to work in Python. But in Matlab, the whole concept of packages/namespaces seems to be an advanced and lesser-used technique. So, your background with other logging frameworks is probably entirely sufficient here and your mental model is correct, and you're just running in to some Advanced Matlab-Specific Syntax Shizz here.
I think SLF4M has a total of like 4 active users at the moment, so the upper limit on how much trouble API changes could cause is pretty small. :) I am leaning toward making this name change. It just seems like a much better naming arrangement to me. Especially because:
seems like a totally reasonable and useful/developer-friendly thing to do. And having the exact same name as Python's logging module would be a user-friendly thing to do that makes it easier to discover SLF4M's code. |
In UserGuide.md,
The suggested usage statement on line 96 seems like a documentation error...
If it worked, then the logger would henceforth refer to the logger object instead of the "package", I think.
But it doesn't work, it produces an error:
Undefined function or variable 'logger'.
(in R2015b, at least)
This works:
The text was updated successfully, but these errors were encountered: