motherlode-logging-tool
v1.2.5
Published
motherlode logging tool
Downloads
14
Readme
MotherLode Logging Tool
Notes and information
Module supports
- Node.js 0.10+, no ES6 shenanigans used that would break your production app
Install
npm install motherlode-logging-tool --save
General logging function
To use the logging function, an one-time config needs to be set.
tool.setConfig( {
hookURL : 'https://hooks.slack.com/services/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',
slackChannel: '#testing',
serverRole : 'testingRole', //Publisher || Publish service || API || Subscriber || BO
serverBrandName : 'testingName', //ETW || AD || AD RTN || FacePop || Next plus || Me!
MLBoDomain: 'http://127.0.0.1:4005' //The domain name / IP of MotherLode BO API
});
Whenever there is an error, this function can be called.
tool.logError(err, ['param1', 'param2'], 404, 'desc');
err
is the error you got. Noted that it needs to be an Error
.
['param1', 'param2']
is the parameter you passed to the error generating function. undefined
can be passed if absent.
404
is the response code for problematic API call. undefined
can be passed if absent.
desc
is a free-writing description to help debug. undefined
can be passed if absent.
In case there is no Error
object but still need to log. The function can be called in this way.
tool.logError(new Error('testing'), ['param1', 'param2'], 404, 'desc');
'testing'
is a short error message.
Config for Dev env
Android hookURL: https://hooks.slack.com/services/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 slackChannel: #android-mobile-app MLBoDomain: http://mldev.cms.appledaily.com.hk
iOS hookURL: https://hooks.slack.com/services/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 slackChannel: #ios-mobile-app MLBoDomain: http://mldev.cms.appledaily.com.hk
Middle layer cms hookURL: https://hooks.slack.com/services/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 slackChannel: #middle-layer-cms MLBoDomain: http://mldev.cms.appledaily.com.hk
Motherlode API hookURL: https://hooks.slack.com/services/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 slackChannel: #motherlode-api MLBoDomain: http://mldev.cms.appledaily.com.hk
Publish service hookURL: https://hooks.slack.com/services/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 slackChannel: #publish-service MLBoDomain: http://mldev.cms.appledaily.com.hk
Publisher hookURL: https://hooks.slack.com/services/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 slackChannel: #publisher MLBoDomain: http://mldev.cms.appledaily.com.hk
Subscriber hookURL: https://hooks.slack.com/services/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 slackChannel: #subscriber MLBoDomain: http://mldev.cms.appledaily.com.hk
UGC hookURL: https://hooks.slack.com/services/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 slackChannel: #ugc MLBoDomain: http://mldev.cms.appledaily.com.hk
Trigger hookURL: https://hooks.slack.com/services/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 slackChannel: #trigger MLBoDomain: http://mldev.cms.appledaily.com.hk
For other usage
Slack Usage Example
slack
- ["hook generator"] (https://ml-monitor.slack.com/services/B0KUG20FN?added=1)
- slack config "attachment"
// require module
var mlt = require( 'motherlode-logging-tool' );
// set config
mlt.setConfig( {
hookUrl : 'https://hooks.slack.com/services/JUST/FOR/EXAMPLE'
});
// slack message format object
var slackMsg = {
channel:'#fortest',
username:'ML-Monitor',
icon_emoji: "https://goo.gl/Gqlxif",
attachments:[
{
"fallback": "",
"color": "warning",
"pretext": "Hi,Support teams! ML-DEV-API have some issues and below is for your report :",
"author_name": "QAT-Monitor at 2016/02/02 15:30",
"author_link": "",
"author_icon": "",
"title": "Client got 404 response",
"title_link": "",
"text": "",
"fields": [
{
"title": "Environment",
"value": "QAT",
"short": true
},
{
"title": "API URL",
"value": "",
"short": true
},
{
"title": "Error Handling",
"value": "please inform dev team to check.",
"short": false
},
{
"title": "Noted",
"value": "10:00 start our daily scrum meeting!",
"short": false
}
],
"image_url": "",
"thumb_url": ""
}
]
};
// send slack message
mlt.slack( null,slackMsg,function( result ){
if( result.state=='success' ) console.log( 'success to send message' );
else if( result.state=='error' ) console.log( 'fail to send message' );
});
You also can write :
var slackMsg = { .... } ( Omission )
mlt.slack(
{
hookURL : 'Your Hook URL'
},
slackMsg,
function( result ){
if( result.state=='success' ) console.log( 'success to send message' );
else if( result.state=='error' ) console.log( 'fail to send message' );
}
);
Email Usage Example
// require module
var mlt = require( 'motherlode-logging-tool' );
mlt.setConfig( {
emailUser:'[email protected]',
emailPass:'your password',
emailTo:'target email addrrss', //e.g. single : [email protected] || multiple : [email protected],[email protected]
emailFrom:'from which email address',
emailHost : 'smtp.gmail.com',
emailPort : 465,
emailSecure : true, // use SSL
emailTitle : 'MotherLode System',
emailUseHTML : false
} );
// send email, Go!
mlt.email( null,
{
emailTitle : '測試,不要問',
emailBody : '就只是測試內容!',
emailUseHTML : false
},
function (result) {
console.log(result);
}
);
You also can write :
// send email, Go!
mlt.email(
{
emailUser:'[email protected]',
emailPass:'your password',
emailTo:'target email addrrss',
emailFrom:'from which email address',
emailHost : 'smtp.gmail.com',
emailPort : 465,
emailSecure : true,
emailTitle : 'MotherLode System',
emailUseHTML : false
},
{
emailTitle : '測試,不要問',
emailBody : '就只是測試內容!',
emailUseHTML : false
},
function (result) {
console.log(result);
}
);
To use Gmail you may need to configure "Allow Less Secure Apps" in your Gmail account unless you are using 2FA in which case you would have to create an Application Specific password. You also may need to unlock your account with "Allow access to your Google account" to use SMTP.
Config
Below is Default Config
var config = {
hookURL : '',
emailHost : 'smtp.gmail.com',
emailPort : 465,
emailSecure : true, // use SSL
emailUser : '',
emailPass : '',
emailFrom : '',
emailTo : '',
emailTitle : 'MotherLode System',
emailUseHTML : false
};