hapijs / good

hapi process monitoring
Other
525 stars 161 forks source link

Creating multiple log files #504

Closed mrbhjv closed 8 years ago

mrbhjv commented 8 years ago

Hello, I'm developing an app where I want to be able to generate multiple log files, one for errors, one for requests and one for ops. Using good 6.x.x I was able to do so. Now I'm not being capable of. It just takes the first one in the list.

I've tried creating one option with the reporters object with three files and it only takes the first one. I've also tried splitting them into multiple options but it's the same. Maybe I'm doing something wrong.

Thanks!

arb commented 8 years ago

I need to see your configuration to help. My guess is that you're using the same reporter name for all the file logging reporters.

mrbhjv commented 8 years ago

Sorry for the lack of format. I did to train myself to post things in here.

I'm using the same reporter name for everyone but when changing it doesn't produce any difference. For this example of code, only the last log file gets created. I tried to go through the code and doc, but there's not much I can follow. Besides I am relatively new to JS itself, I am just trying to use the best resources I can run into. Sorry if my issue is kinda dumb :)

const options = {
    ops:{
        interval: 5000
    },
    reporters: {
        file: [{
            module: 'good-squeeze',
            name: 'Squeeze',
            args: [{ops: '*'}]
        },{
            module: 'good-squeeze',
            name: 'SafeJson'
        },{
            module: 'good-file',
            args: ['./logs/hapi-process.log']
        }],
        file: [{
            module: 'good-squeeze',
            name: 'Squeeze',
            args: [{response: '*'}]
        },{
            module: 'good-squeeze',
            name: 'SafeJson'
        },{
            module: 'rotating-file-stream',
            args: ['hapi-requests.log',
            {
                size: '10000B',
                path: './logs'
            }]
        }],
        file: [{
            module: 'good-squeeze',
            name: 'Squeeze',
            args: [{error: '*'}]
        },{
            module: 'good-squeeze',
            name: 'SafeJson'
        },{
            module: 'rotating-file-stream',
            args: ['hapi-error.log',
            {
                size: '1000B',
                path: './logs'
            }]
        }]
    }
}

server.register({
    register: require('good'),
    options: options
}, function(err) {

    //something
});
mtharrison commented 8 years ago

You can not have multiple properties with the same name in JavaScript (nothing specific to Good here). To start with, you probably need to name them differently.

screen shot 2016-07-10 at 23 22 04

cshanejennings commented 8 years ago

This threw me as well and I think it's a potential interpretation quirk in the documentation.

I assumed that the keys in reporters hash were reserved names based on the type of reporting. It wasn't until I saw this thread that I realized the keys were arbitrarily named (at least I'm assuming they are). I think something that could help would be to provide an example of two files being logged out where the keys are labeled something obviously unreserved like "mylogfile1" and "mylogfile2".

OR... to explain the purpose of the keys in the hash and provide some comments on what each section is actually doing. Anyhow, hope that's helpful!

EDIT: after noticing the API documentation link I see this is clearly explained. doh! I think just a simple "View the api documentation for more information on reporters" next to the examples could help reduce confusion for those of us moving fast and skimming? I'm following along with a tutorial that's out of date and already a lot farther down the rabbit hole than I anticipated, hence the lack of attention to detail.

arb commented 8 years ago

PR documentations are always welcome.

cshanejennings commented 8 years ago

done, let me know if that works for you or if you'd like me to tweak it. Thanks!

lock[bot] commented 4 years ago

This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions.