Skip to content
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

How to load the logger inside a namespace in a package #1

Open
marcosfrenkel opened this issue Jun 13, 2023 · 1 comment
Open

How to load the logger inside a namespace in a package #1

marcosfrenkel opened this issue Jun 13, 2023 · 1 comment

Comments

@marcosfrenkel
Copy link

Hello, This might not be the correct place to ask this question but I am not sure where to go.

I am trying to use the Logger package to log a few functions in a package I'm writing. The functions in question live inside different namespaces. My problem comes when I try to call the logger inside of those namespaces, there is no way I could find to create an instance of a Logger and actually use them after I build my package and load it in a different workspace.

Any help would be appreciated, if this is not the correct place to ask for questions please close the issue and point to a better location.

@aplteam
Copy link
Owner

aplteam commented Jun 14, 2023

Let me repeat the question: you have, say, a namespace Foo and inside Foo, say, namespaces A and B, and you want to be able to use an instance of Logger from Foo, A and B, correct?

Let's assume you are creating an instance of Logger named MyLogger in your constructor. Then you can call MyLogger.Log from inside Foo, so that's just fine.

From inside A and B (and also other namespaces even more deeply nested) you have several options:

  • You can use the ##.MyLoogger syntax.

    This gets cumbersome if the nesting levels go deeper: ##.##.MyLogger does not look nice, does it?!

  • You can inject references into A and B. From inside Foo:

    (A B).MyLogger←Mylogger
    

    Now you can call MyLogger.Log from all namespaces.

    This solution is preferable when there are plenty of places the package is called from.

  • You may create a reference on demand like this:

    Foo.A.⎕FX ↑'{r}←Log msg;MyLogger' 'MyLogger←##.MyLogger' 'r←MyLogger.Log msg'
    

    In this example, that does not make too much sense, but you get the picture: with a package offering many different calls, this is a pretty neat technique.

  • Use ⎕PATH - I strongly advise against this.

    The more complex an application gets the more difficult it gets to keep track of what is actually happening, yet complexity is why a solution was needed in the first place.

In case I misunderstood your question please clarify.

If you are happy with my answer please close the issue, otherwise let me know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants