Skip to content

Conversation

@kevinresol
Copy link
Collaborator

Adding message formatter option for the Loggers.

But I am not sure how to make it configuration-friendly. Any ideas?

Now I use it in an ugly way:

function myFormatter(m:Message):String {
    // ...
}

for(l in ufrontApp.logHandlers) 
    if(Std.is(l, ServerConsoleLogger)) 
    {
        @:privateAccess cast(l, ServerConsoleLogger).messageFormatter = new BasicMessageFormatter(myFormatter);
    }

It is a simple class implementing UFMessageFormat and use a Message->String function as its format() implementation
@jasononeil
Copy link
Contributor

Interesting idea! I like what you're getting at, but I think it does need some work still.

A few thoughts:

  1. What is your aim? Do you want to create a new format function (specific for your app) that can be used on all the different loggers? Or do you just want to reduce code duplication?
  2. If your aim is to change the log format across your app, maybe we need the format function to just return the log message as a String (or even an Array<Dynamic>), and then each logger knows what to do with it (format it for remoting, make it a JS console.log call, etc)?
  3. For configuration, you could set a message formatter in your UfrontConfiguration. UfrontApplication would then inject it into the application injector, and it would be available when the Logger modules are constructed. This is assuming that we do it in a way where one MessageFormatter can work for all our different "logger" modules.

@kevinresol
Copy link
Collaborator Author

  1. My objective is the former. I would like to have a customized message format
  2. That's true, I can modify it a bit.
  3. Ok, but do you prefer a class instance or just a function?

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

Successfully merging this pull request may close these issues.

2 participants