ufront / ufront-mvc

The core MVC framework that powers ufront
MIT License
17 stars 15 forks source link

Message Formatter #40

Open kevinresol opened 8 years ago

kevinresol commented 8 years ago

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);
    }
jasononeil commented 8 years ago

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 commented 8 years ago
  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?