I want to write into a txt file all the logs of my nodeJs program.
I'm using node script-file.js >log-file.txt, but it overwrites the same txt file every time it runs.
Is there a parameter to add so that the title of the generated log-file.txt includes the date and time like this : log-file-18-06-2010-11-57 (dd-mm-yyyy-hh-mm)?
Thanks to a friend of mine, I was able to answer my question.
As the solution node script.js > log.txt 2> errors.txt generates only one file of logs and one file of errors. Putting >> instead of > permit to append the logs and errors, but the notion of time is lost.
The SOLUTION is to simply do node script.js >> log-error.txt 2>&1 and it generates one file, where both logs and errors are transcribed into this file.
You have to console.log the date at the top of the script and it makes a reliable log-errors file.
To add the date (it will help beginners) just write this :
var today = new Date(); console.log(today.getDate() + '-' + today.getMonth() + '-' + today.getFullYear() + ' ' + today.getHours() + ':' + today.getMinutes() + ':' + today.getSeconds() + '.' + today.getMilliseconds())
How about using package? I think this is very simple way.
Here's the awesome log file package
Related
I am trying to show the last time I made a published change and the current library version
I created a data element Global - Example:
return "DTM:" + _satellite.publishDate.split(" ")[0] + "|" + "Adobe:" + s.version;
Then I set a prop to my %Global - Example%.
It doesn't work. So I tried to debug in the console. When console.log("DTM:" + _satellite.publishDate.split(" ")[0] + "|" + "Adobe:" + s.version); it works in the console and I get the the last publish date and the current version of the library. However, it won't work for some reason in dtm.
Using a Data Element in this case will have an impact on timing.
If you add your code to the Adobe Analytics Custom Code section of a rule or AA Global Code you should be able to set your prop just fine.
s.prop1 = _satellite.publishDate.split(" ")[0] + "|" + "Adobe:" + s.version);
Hope this helps.
Edit: Previously only HTML was there but in new update even Javascript works but purely Javascript ... I can't add HTML there...
I am working on a WordPress site, I need to display an image dynamically in a site. Image source will be like:
site.com/files/year/month/date/img1.jpg
But in my theme I can only input either HTML or JS there... generally if it is a static site then we can only use that image but my image gets updated daily... i.e.
today it will be site.com/files/2015/4/13/img1.jpg
tomorrow it will be site.com/files/2015/4/14/img1.jpg
How can I achieve this?
var image = document.getElementById('yourImagesId');
var date = new Date();
var url = 'site.com/files/' + date.getFullYear() + '/' + (date.getMonth() +1) + '/' + date.getDate() + '/img1.jpg';
image.setAttribute('src',url);
HTML is Hyper-Text Markup Language. It isn't "code" in the sense that it doesn't have any logic or power. It exists to literally markup your copy; that is, it's primary use is to define the layout of the content of your page.
To do anything dynamic, you need an actual coding language that can perform actual logic functions, so you'll have to utilize JavaScript (or PHP, as you're in Wordpress).
I'd be lying if I said I had experience in Wordpress's environment, but I'd imagine that googling "wordpress dynamic image path plugin" would possibly yield some tangible results.
Not sure what do you mean only with HTML, as for Javascript:
var currDate = new Date();
var url = "site.com/files/" + currDate.getFullYear() + "/"
+ (currDate.getMonth() + 1) + "/" + currDate.getDate()
+ "/" + imageName + "." + imageFormat;
getMonth will get the month as a number from 0 to 11 so you add 1 if needed to have it as 1 ~ 12.
JSFiddle Example
Be aware that JS takes the date and time from the client.
window.location="http://test.rgniyd.com/test1/?q=node/36/"&dept="+ dept +"&bath="+
bat +"&month=+month+"&year="+year+"&semester="+sem";
how to redirect the page to http://test.rgniyd.com/test1/?q=node/36/ with values in
JavaScript. the above code is not working , please help or please suggest me how to redirect page without clearing the session values in JavaScript
Change your JavaScript as
window.location="http://test.rgniyd.com/test1/?q=node/36/&dept=" + dept + "&bath=" + bat + "&month=" + month + "&year=" + year + "&semester=" + sem;
Because you have misplaced double quotes "
You have messed up (a bit) the string concatenation..
window.location="http://test.rgniyd.com/test1/?q=node/36/&dept="+ dept +"&bath="+
bat +"&month="+month+"&year="+year+"&semester="+sem;
I have to display datetime value on my real time page and i have done following jquery function for that.
function DisplayTimer() {
var x = new Date();
$('#<%=lblTimer.ClientID %>').html(x.toString());
setTimeout('DisplayTimer()', 5000);
}
now i have timezonid value in my session object how can i convert above date value to custom timezone using timezonid session value and also want set datetime format as per culture of user's browser through this jquery function. I have solution in server side code so using [webmethod] i can do that it will make separate request for that every 5 second so i would like to do that without server side interaction. please help me if anyone done this type of logic.
Thanks in adavance.
Change your code with:
var ClientDatetime = x.getMonth() + "/" + x.getDate() + "/" + x.getYear() + " "
+ x.getHours() + ":" + x.getMinutes() + ":" + x.getSeconds();
take one hidden variable hdnClientDateTime with runate = server and set value as following
hdnClientDateTime.value = ClientDatetime;
Now, Pass hdnClientDateTime.value variable in your server side Datetime format function and assign the value into label like this:
$('#<%=lblTimer.ClientID %>').html(Result);
I want to do something like
var date = new Date();
var pretime = date.getTime();
$.post(
"ajaxfile.php",
object,
function(data) {
var totalTime = date.getTime()-pretime;
$("#feed").append("Time: " + totalTime + "<br/>" + pretime + "<br/>" + date.getTime() + "<br/>");
});
});
That is, measure how long the AJAXcall lasts before I get a response. But the print from this callback function is:
Time: 0
1326184886814
1326184886814
What is the solution to this?
getTime() is returning the same value because you are reusing the same Date() object. You need to create a new Date object:
var date = new Date();
var pretime = date.getTime();
$.post("ajaxfile.php", object, function(data){
var date2 = new Date();
var totalTime = date2.getTime()-pretime;
$("#feed").append("Time: " + totalTime + "<br/>" + pretime + "<br/>" + date.getTime() + "<br/>");
});
});
I'm no Javascript expert, but it seems to me that you're creating a single Date object which (if it's similar to Java's Date object) stores the date/time at the point it was created, and then using that same date object twice - i.e. comparing the start date/time to itself.
Try creating a second Date object inside the AJAX callback function to capture the end time.
If you are just interested in the time, without saving it somewhere, you can use Google Chrome's developer console.
press F12, go to "Network" tab, execute your Ajax call, and you can see a timeline of how long it takes you to get a response.
If you use firebug to debug your Javascript code take a look at the console. It will tell you how many miliseconds your ajax call takes :)
Also, if you don't use firebug, what are you waiting for? It is awesome for debugging and will save you lots of time!