clux / logule

A multi-transport, peer-dependent logging library for nodejs - UNMAINTAINED
MIT License
35 stars 5 forks source link

path to configuration file #3

Closed vpetrov closed 12 years ago

vpetrov commented 12 years ago

logule loads .logule files from the current working directory using 'confortable' (sic). This means that a module in node_modules cannot ship its own .logule file, because the current working directory doesn't point to the module folder. Polluting the user application with .logule files (which should belong to my module) is not a good idea.

Please allow for configuration options to be specified as JSON objects or for passing in a path to a configuration file.

Thanks!

clux commented 12 years ago

'confortable' (sic)

The mispelling is intentional, it's a pun on conf.

a module in node_modules cannot ship its own .logule file

This is precisely the point. If rogue modules used logule along with your app, you would want consistency between them (and potentially dependency injection at the borders). If modules were able to override the application's defaults you will not be able to fix inconsistent styles between the two.

The only possible case I can see per-module configuration having any credibility is if you are making a preferGlobal CLI module. And even then, it's probably in your best interest to pass customization on to the user in case they too start using logule for something else, and wants consistency.

vpetrov commented 12 years ago

Thank you for replying so quickly!

If modules were able to override the application's defaults

Why would they override application defaults? A better approach would be to prioritize .logule files:

cwd > custom path > logule path

This would allow the application to override settings used by all modules, if it needs to, while still allowing modules bundling logule to customize their own output.

edit: clarified last sentence

clux commented 12 years ago

Ah, yes, I can see that being desirable.

I could possibly initialize logule with a config from the requiree's local directory, then override it (like before) by any potential suitor from confortable's recursive search. Simply having a method to set the custom path would not do, as people could then override the app, unless i once protect it or something. Not as nice that though. I think module.parent may hold the key.

Let me think about it for a day.

clux commented 12 years ago

I started rewriting confortable this morning and it seems like this is fine. The priority would be:

cwd > ../cwd > ... recursively up to HOME || root > fallback > defaults

where fallback in this case gets fed in from logule as the path of the parent i.e.

var fallback = path.join(path.dirname(module.parent.filename), '.logule');

Does this seem good to you?

vpetrov commented 12 years ago

This would be perfect. Thank you!

clux commented 12 years ago

logule @0.8.2 now exists with this functionality : )