log4javascript - no trace messages appear - javascript

I'm using log4javascript version 1.4.3.
In my app it works fine for all log levels except trace. To simplify things and make sure that the problem is not within my app I made an example using the authors sample code as an example and added a setThreshold(log4javascript.TRACE), then added a line to generate a trace entry (I also deleted the lines from his example that are relevant only to an ajaxAppender leaving just the popUpAppender).
When I run the code the error and debug messages appear in a log4javascript popUp window but no trace message.
Evidently I don't correctly understand the use of the trace level or the configuration for trace messages. If someone could point out the error of my ways then I can fix my app logging.
Sample code that fails below.
<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>log4javascript example from manual</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<meta name="author" content="Tim Down - tim#log4javascript.org" />
<meta name="description" content="log4javascript, a logging framework for JavaScript based on log4j" />
<meta name="robots" content="all" />
<script type="text/javascript" src="/tracker/libraries/log4javascript.js"></script>
<script type="text/javascript">
//<![CDATA[
var log = log4javascript.getLogger();
var popUpAppender = new log4javascript.PopUpAppender();
var popUpLayout = new log4javascript.PatternLayout("%d{HH:mm:ss} %-5p - %m%n");
popUpAppender.setLayout(popUpLayout);
// new line below
popUpAppender.setThreshold(log4javascript.Level.TRACE);
log.addAppender(popUpAppender);
log.debug("Debugging message (appears in pop-up)");
log.error("Error message (appears in pop-up and in server log)");
// new line below
log.trace("Trace message");
//]]>
</script>
</head>
<body>
<h1>log4javascript example from manual</h1>
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
var pageTracker = _gat._getTracker("UA-448786-3");
pageTracker._initData();
pageTracker._trackPageview();
</script>
</body>
</html>

The problem is that the logger has a threshold level as well, which is set to DEBUG by default. Add the following line before calling log.trace():
log.setLevel(log4javascript.Level.TRACE);

Related

How read external iframe via PHP or JavaScript

I want to track my package sent via the local post service: http://tandt.posta.sk/en.
With the tracking information, for example, RF166699170SK, I can locate the package.
but when I want to read it via PHP for example curl_setopt, via file_get_contents, or another method, I read only HTML code but in output missing text for example "Item posted at post office Dlhé Pole" which I can see on page.
because this page use iframe with some private method
http://www.posta.sk/en/sps-embed#tnt?q=RF166699170SK
but when I try to read this page (iframe), output missing information about package for example "Item posted at post office Dlhé Pole".
Output:
<!DOCTYPE html>
<html class="embed">
<head>
<link href="/sps/style.css?1450227250" media="screen,print" rel="stylesheet" type="text/css" />
<link href="/sps/print.css?1445466449" media="print" rel="stylesheet" type="text/css" />
<title>Slovenská pošta</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
<meta name="format-detection" content="telephone=no">
<meta name="google" value="notranslate">
<script type="text/javascript">CONFIG={"api":"http://api.posta.sk/private","tntShare":{"en":"http://tandt.posta.sk/en/items/{number}","sk":"http://tandt.posta.sk/zasielky/{number}"},"lang":"sk","home":"http://www.posta.sk","embed":true}</script>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=true"></script>
<script src="/sps/script.js?1457665771" type="text/javascript"></script>
</head>
<body>
<script type="text/javascript">
//<![CDATA[
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
//]]>
</script><script type="text/javascript">
//<![CDATA[
try {
var pageTracker = _gat._getTracker("UA-9600731-1");
pageTracker._setDomainName("posta.sk");
pageTracker._initData();
pageTracker._trackPageview();
} catch(err) {}
//]]>
</script>
</body>
</html>
Is it possible to read about this parcel via PHP or JavaScript?
If you inspect network connection of the page you linked you can see that there some data is loaded via JSON request. In your example data is requested from http://api.posta.sk/private/search?q=RF166699170SK&m=tnt
Maybe it would be the easiest way to get data direct from this API instead of trying to parse the result. The key is the same. You can convert the response in php like this:
<?php
$packageKey = 'RF166699170SK';
$data = json_decode('http://api.posta.sk/private/search?q='.$packageKey.'&m=tnt', TRUE);
?>
But I don't know if it's allowed by your postal service. You should ask if it's prohibited to do that.
There is an open API available for package tracking. Here you will find more information and documentation: https://www.posta.sk/informacie/api-dokumentacia
Example query: http://api.posta.sk/tracking?l=en&p=1&q=RF166699170SK

Why doesn't the google search API show images?

When I use the google search api example from here
It doesn't show me any results for Images.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>Hello World - Google Web Search API Sample</title>
<script src="https://www.google.com/jsapi"
type="text/javascript"></script>
<script language="Javascript" type="text/javascript">
//<!
google.load('search', '1');
function OnLoad() {
// Create a search control
var searchControl = new google.search.SearchControl();
// Add in a full set of searchers
var localSearch = new google.search.LocalSearch();
searchControl.addSearcher(localSearch);
searchControl.addSearcher(new google.search.WebSearch());
searchControl.addSearcher(new google.search.VideoSearch());
searchControl.addSearcher(new google.search.BlogSearch());
searchControl.addSearcher(new google.search.NewsSearch());
searchControl.addSearcher(new google.search.ImageSearch());
searchControl.addSearcher(new google.search.BookSearch());
searchControl.addSearcher(new google.search.PatentSearch());
// Set the Local Search center point
localSearch.setCenterPoint("New York, NY");
// tell the searcher to draw itself and tell it where to attach
searchControl.draw(document.getElementById("searchcontrol"));
// execute an inital search
searchControl.execute("VW GTI");
}
google.setOnLoadCallback(OnLoad);
//]]>
</script>
</head>
<body>
<div id="searchcontrol">Loading</div>
</body>
</html>
The option is there through this line
searchControl.addSearcher(new google.search.ImageSearch());
However the results say 0.
Shouldn't there be at least a couple of images? I think a couple of weeks ago when I tried it, it still worked?
Any idea?

Access comment nodes outside <html> tag

I'm developing a chrome extension that reads html comments from a page and render them in an action popup.
However, I don't know how to (and if it's possible) to fetch some comments that are before and after the <html> tag. For example:
<!-- test test test -->
<DOCTYPE html>
<html>
...
</html>
In jQuery, $("html").before() and $("html").after() both returns the same as $("html").
Is it possible do fetch those types of comments using either jQuery or pure Javascript?
Edit: the page with the comments looks like this:
<!-- Comment I'd like to fetch -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-us" lang="en-us" >
<head>
<title>Featured Designers for WOMEN</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<meta http-equiv="Content-Script-Type" content="text/javascript" />
<meta http-equiv="Content-Style-Type" content="text/css" />
With this document:
<!-- comment 1 -->
<!DOCTYPE html>
<!-- comment 2 -->
<html>
<body>
hello world
</body>
</html>
You get the first comment like this:
document.firstChild.nodeValue
The second comment is found like this:
document.childNodes[2].nodeValue
To get all comments underneath document:
var nodes = document.childNodes;
for (var i = 0, len = nodes.length; i !== len; ++i) {
if (nodes[i].nodeType === 8) {
console.log('Found comment' + nodes[i].nodeValue);
}
}
document.firstChild should do it.
$("html").siblings(); This will return all the dom object elements at the same level as the html tag I believe. I wanted to confirm by using JSfiddle but I'm receviing Javascript errors on their website using IE8 right now. I can confirm later when I get home if it doesn't work for you in your testing.

"Permission denied" with Internet Explorer and jQuery

I try to do an AJAX call with jQuery and $.post in Internet Explorer, but all I get is an error saying "Permission denied". The problem is kinda weird since it occurs only when I access a page after I was on any other page.
For instance I type the URL in the adress line and let IE load the page. Then I click on a button so the script should start loading JSON data. (The script providing the data lies on the same server and I access it with a relative URL, so using a different domain is not the problem here. Even tried to use a absolute URL with the same host part.)
But when I refresh the page then and try it again it works! Same thing when I come to that page from another page. At first nothing works, but when I click "refresh" everything is fine.
IE gives me the error message "Permission denied" while in every other browser I don't notice this behaviour. Since I have tried many things and still cannot imagine where the problem lies I'd like to ask you what you think the problem might be?
edit:
A small example:
test.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de">
<head>
<script type="text/javascript" src="/ietest/jquery.js"></script>
<script type="text/javascript" src="/ietest/test.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
Test
</body>
</html>
ajax.html
It works!
test.js
$(document).ready(function(){
$( 'a' ).click(function(){
$.post( '/ietest/ajax.html', function( data ) {
alert( data );
});
});
});
Try it here: http://t1318.greatnet.de/ietest/test.html
From the post on jquerys forum here, you have to have the content type meta as the first item in your head tag.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="/ietest/jquery.js"></script>
<script type="text/javascript" src="/ietest/test.js"></script>
</head>
<body>
Test
</body>
</html>
If its local (localhost), then for security reasons you have to have the full path.
In my case, changing the jquery version worked. Instead of using version 1.9.1, now I'm using 1.12.4 and it works.

javascript function wont fire in IE

I have this code:
<body onLoad="subcatSelection();">
The function is inside a .js file which is included with this code:
<script type="text/javascript" src="bincgi/search_lists.js"></script>
The function contains an alert('hello'); just for testing purposes to see if it gets called, but it doesn't.
The "Page error" or whatever its called on the bottom left corner of Explorer 6 is displayed and when double clicking it it assumes there is an error on LINE x ROW y, which is the body-onload event.
Anybody has an ide?
If you need more input let me know... Thanks
UPDATE:
Some html before the onload event...
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript" src="bincgi/search_lists.js"></script>
<script type="text/javascript" src="bincgi/jsfunctions.js"></script>
<script type="text/javascript" src="bincgi/calendar_eu.js"></script>
<link href="bincgi/main_styles.css" rel="stylesheet" type="text/css">
<link href="bincgi/calendar.css" rel="stylesheet" type="text/css">
<!--[if lt IE 8]>
<link href="bincgi/main_styles_ie_lt7.css" rel="stylesheet" type="text/css">
<![endif]-->
<style type="text/css">
body {
background-color: #fffec7;
background-image: url(Graphics/test_bgr.gif);
background-repeat: repeat-x;
}
</style>
</head>
<body onLoad="subcatSelection();">
If [Juriy] answer didn't work, then try calling your function in your page:
<script type="text/javascript" src="bincgi/search_lists.js"></script>
<script type="text/javascript" >
alert("first test");
subcatSelection();
</script>
If that doesn't work, it has to be a trivial problem (e.g., file in wrong location, need to re-start browser, clean cache, etc.)) that is giving you troube.
As far as I see from the comments, the problem might be in the other line of search_lists.js (that might be before subcatSelection definition). IE just stops parsing it and doesn't load the function correctly. Try to leave a single function definition in that file and see what happens:
function subcatSelection() {
alert ("Hello");
}
It may be possible that there's a syntax error that it is avoiding the correct definition of the function. Make that function the only function in your .js file, put your test alert("hello!), and try again.
Check the permissions, you are running inside a cgi bin folder which operates a bit different
I would also suggest not mixing your js files with your CGI (who uses cgi anymore)
Because you have the problem on IE6 only from what I understand, I would try to first use Fiddler to determine if your file is downloaded correctly, if it is then I would modify the content of search_list.js to be:
alert('Before def');
function subcatSelection() {
alert('In subcatSelection');
}
alert('After def');
Then create a page like this to see if you get the alerts in that order: 'Before def', 'After def', 'Before Call', 'In subcatSelection', 'After Call'.
At that point, you should know for sure where is the problem if it's still there. If you don't have the error, then start plugging back the pieces one by one (move the call in body onload then try, re-add the code in search_list.js then try, re-add the other JS includes then try, etc.)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript" src="bincgi/search_lists.js"></script>
<script type="text/javascript">
alert("Before Call");
subcatSelection();
alert("After Call");
</script>
</head>
<body>test</body></html>

Categories

Resources