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

Feature/logger refactor #86

Open
wants to merge 21 commits into
base: develop
Choose a base branch
from
Open

Feature/logger refactor #86

wants to merge 21 commits into from

Conversation

qejk
Copy link
Member

@qejk qejk commented Apr 19, 2016

Refactors Space.Logger, its initialization, and removes unnecessary use of Space.log global var. Enables to pass multiple transports to underlying library for logging (winston) through application config like:

My.App = Space.Application.define('My.App', {

  configuration: {
    appId: 'My.App',
    log: {
      enabled: true,
      winston: {
        console: {
          enabled: true,
          minLevel: 'info'
        },
        transports: [
          new winston.transports.Console({
            name: 'console',
            colorize: true,
            prettyPrint: true
          })
        ]
      }
    }
  },
})``` 

@@ -165,11 +170,47 @@ class Space.Module extends Space.Object
this[hook] ?= ->
this[hook] = _.wrap(this[hook], wrapper)

_setupLogger: ->
config = Space.configuration.log
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we can do away with the Space.configuration as that was only needed since we were previously initialising the logger instance outside the module chain. This will be really nice to see gone

@rhyslbw
Copy link
Member

rhyslbw commented Apr 19, 2016

Nice start @qejk , really excited to see this design fleshed out!

cc @DominikGuzei @darko-mijic
Adam and I have been discussing this improvement to clean up a few issues with the first implementation of the logger and to allow for flexibility with transports. As part of this change we also scoped the ability to disable the built-in console logger.

Please review

qejk added 4 commits April 24, 2016 13:47
… multiple logging adapters in Space.Logger, adds adapter for console, winston logging libraries, wires everything up in module.coffee
…ds setMinLevel, adds removable transports at winston adapter
@DominikGuzei
Copy link
Member

Great work here, the only thing i'm concerned with is the default logger complexity this brings into space:base as we discussed, it would be better to move into more modularity instead. What do you think?

Another problem is the new code in Coffeescript 😜 we want to move to ES6

@rhyslbw
Copy link
Member

rhyslbw commented Apr 25, 2016

We did discuss the idea of breaking out the console (default) logger, but deferred the idea, as the first step was just to make the code modular. It's a little more complex due to the fact that space:base calls the log method and it's within the module init that we want a logger instance created, but now that @qejk has introduced the concept of an adaptor the base logger class is essentially a noop logger. So we could move the server and client logger implementations into a separate package/s which removes the winson dependency in space:base, and makes it easy to add logging only if desired (or even write your own adaptor).

I vote for the approach with the client and server adaptors in separate packages, because in production a client logger makes little sense, so can see it purely as a development tool.

Also @qejk will be converting to ES6 when the design is fleshed out.

@DominikGuzei
Copy link
Member

DominikGuzei commented Apr 26, 2016

Yes, moving this into a general purpose configurable logger package that has no idea about Space will be the best option. This is the way forward!

Remember, packages like this are the goal:
https://github.com/meteor-space/template-controller

very small, focussed and highly documented (because it's easy!)

@qejk
Copy link
Member Author

qejk commented Apr 26, 2016

@DominikGuzei Changes will be moved to ES6 when I'm fully happy with them. Don't have much time currently and I'm faster with CS when prototyping.

Normally this would be like Rhys said - noop logger that can handle multiple logging libraries with granular control over them however developer pleases(and by that how he write his own adapter wink wink).
If there is transport that winston does not support - someone can use his own library. The big question is: if we actually require such thing in first place, since specs for that change initially were quite simple.

With JS there is limited way how to handle things because of lack of interfaces, so some sacrifices must be made when using typical OOP patterns, so would like to hear if this is the right direction to go.

Currently I would like to refactor only this ugly pice of code:

_loggingConfig: () ->
and ensure that everything else related to initialization of Space.Logger is ok around with module vs app initialization, since I know only how things works partially.

Moving this to another module will require rethinking everything from ground up, since

@log.debug("#{@constructor.publishedAs}: initialize")
debugging starts before module initialization.

@DominikGuzei
Copy link
Member

Yep, that's another possibility – make it configurable in a way that space:base does not depend on winston and anyone can use whatever they like 😉

})


});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@qejk Do you have .eslintrc checking the format? This should be a new line

@rhyslbw rhyslbw removed their assignment Mar 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants