herbsjs / herbs

A domain-first framework. Code your domain and your infrastructure will follow
https://herbsjs.org/
MIT License
427 stars 14 forks source link

Log glue - herbs2winston #6

Open jhomarolo opened 2 years ago

jhomarolo commented 2 years ago

As we are using practically all herbs projects with winston + kinesis, with code repetition in several places, I imagined that we can create a new herb glue that automatically connects herbs with winston (and still remains compatible for winston connectors ), possible a herbs2winston glue;

I would like to know if you think that there would be a real gain in this implementation and how it could work (breaking as little as possible of what we have today)

Add: Imagine just like the buchu that you can put in .env the audit for it to blow the exception, we can put this glue to log the entire use case execution that happens, I don't know, it was just an idea.

Add: I imagine the lib going more towards, for example, automatically auditing all usecases with a predefined (winston) transport. Or log all usecases that return error automatically.

italojs commented 2 years ago

did you have some suggest for the log metadata and log string/object format? I will call it like an lib? all usecases will be logger automagincally? how will be the glue usage?

jhomarolo commented 2 years ago

As we have many "configuration files" of the configuration of logs, of Winston and his transporters, we could create a lib that already comes pre-configured and that automatically collects the audit of all use cases and other layers of herbs (infra, API, repo, etc) in a configured way.

I will call it like an lib? all usecases will be logger automagincally? how will be the glue usage?

Yes, and inside this lib the usecase.audit() you be called automatically

The idea here is to reduce a lot of config files and audit everything without concern if the dev is calling this or not

italojs commented 2 years ago

so, the usage could be:

class MyLogger extends Herbs2Winston{

constructor(){
   super({
       streamName: "KINESIS_FIREHOSE_LOGGER_NAME",
       firehoseOptions: {
           region: "KINESIS_LOGGER_REGION",
           accessKeyId: "KINESIS_LOGGER_ACCESS_KEY_ID",
          secretAccessKey: "KINESIS_LOGGER_SECRET_ACCESS_KEY"
       },
       messageFormat: {
               error: (logTxt) => `if I dont specify this function, we follow with a default herbs format`,
               info: (logTxt) => `if I dont specify this function, we follow with a default herbs format`,
               audit: (logTxt) => `if I dont specify this function, we follow with a default herbs format`
               [...]
       },
       levels: {
             error: 0,
             audit: 1,
             info: 2
            [...]
      }
})

}

what do you think?

italojs commented 2 years ago

@jhomarolo