Best approach to Logging in javascript [closed] - javascript

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I want to console.log but then turn it off in production without deleting the logs statements.
What are other logging levels and how can i utilise them?
What benefits do logging libraries such as log4js offer?

Place this code in your webpage
if(window.location.hostname=="example.com"){
console.log = function(){
return;
}
}
What it will do is, if the domain name is example.com it will override the console.log functionality and it will print nothing in console.
This way it will also work in your local environment.

var myAPI={isLogged:false};
(function(api){
if(window.location.hostname=="dev.example.com"){
myAPI.isLogged=true;
}
api.log=function(msg,level){
if(!level){level='log'} //can be : warn, info, error, debug or log
if( myAPI.isLogged){
console[level](msg);
}
};
})(myAPI) ;
Then , use :
myAPI.log(new Date()+' This is security check ');
or
myAPI.log(new Date()+' Wrong password ','error');

Related

How to check if a certain user was mentioned [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I am trying to check if a user has been mentioned (#user) in a message. This is what i currently have:
} if (message.content.includes('<#796406791323516999>')) {
message.channel.bulkDelete(1);
message.channel.send('User mention was detected')
}
(This is wrapped in a client.on detecting when a message is sent)
What am i doing wrong here?
You can use Mentions#members#has using the member's id to check if there were any mentions, and if the member was one of the mentions.
const mentions = message.mentions.members;
if (!mentions) return message.channel.send('No Mentions Error Message.');
if (mentions.has('796406791323516999')) {
message.channel.bulkDelete(1);
message.channel.send('User mention was detected');
}

How can I detect if user has successfully alerted a thing (I'm making an XSS game) [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
The page just echoes the user input using GET. I have no idea on what concept to apply to detect if the user has alerted something
The easiest approach would probably be to replace the alert method with your own.
const log = [];
alert = function(alert) {
return (value) => {
log.push(value);
alert(value);
};
}(alert);
alert("Hello!");
console.log(log);

How to show method declaration in NodeJs [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
is there any way to show function declaration. e.g what it takes as parameters and what it returns in CLI? as like "tinker in laravel"
I searched over internet but found nothing.
I am not sure if I correctly understand your question. To find out what a function looks like, including its parameters (and all its code including what it returns), you can do a (slightly dirty) hack like this:
function a(b,c) {
return b + ", " + c;
}
console.log(a.toString());
Output:
'function b(a,b){return a+" " + b}'
Alternatively, if you are looking for documentation, for most NPM modules and note itself, there is solid API documentation. See https://nodejs.org/api/ for example.

Correct inputs for this? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I am trying to take a survey you can say: I am asking a question if they work out a lot or not, then I have different questions for them if they do or don't work out a lot. And then I am asking them if they are female or male. My goal is to give them feedback based on all three things, sex,work out or not, and how they answer questions.
Currently all of my questions go to the same inputs, for the 2 sets of questions. My code is to long to post so I will add a fiddle below .
$('.myOptions').change(function () {
$('.list').removeClass('active');
$('.' + this.value).addClass('active');
});
http://jsfiddle.net/7xM2f/12/
Your braces are not properly nested. For example you have something like
if (tt == 'Male') {
//some code
if (tt == 'Female') {
You are missing the closing brace for the Male block.
There are several such errors. You should properly indent your code to make these easier to track and pay attention to the error console.
http://jsfiddle.net/ExplosionPIlls/7xM2f/15/

I cannot find this syntax error [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I'm going to feel like a complete idiot once this is pointed out to me, but I've got a syntax error I cannot figure out where the issue is coming from. Here is my code (error appears on last line but I doubt its that line that caused that):
// handle GCM notifications for Android
function onNotificationGCM(e) {
switch( e.event )
{
case 'registered':
if ( e.regid.length > 0 )
{
// Your GCM push server needs to know the regID before it can push to this device
// here is where you might want to send it the regID for later use.
PushWoosh.appCode = "33F93-5013B";
PushWoosh.register(e.regid, function(data) {
alert("PushWoosh register success: " + JSON.stringify(data));
}, function(errorregistration) {
alert("Couldn't register with PushWoosh" + errorregistration);
});
}
break;
Thanks guys, I'm feeling like an idiot here and had a frustrating day.
Your onNotificationGCM() function is not closed, and neither is the switch block contained within it. The JavaScript parser is expecting to see two additional close braces (}) but the input file terminates before they are seen.
My guess is that you need to add these two braces after your break; statement, prior to the assignment of PushNotification.prototype.register.

Categories

Resources