我正在尝试将控制台调用重定向到log4javascript库。
所以基本上,对console.log
的任何调用都会调用log.info
,log
为Log4javascript实例。
但是当它调用log.info
时,我得到一个“Fonction attendue”错误(法语),这基本上意味着“功能预期”。
我也尝试从IE8控制台调用log.info
,同样的故事。
我不认为它与脚本有关,但是如果是这样的话,那就是:
(function (fallback) {
fallback = fallback || function () { };
// function to trap most of the console functions from the FireBug Console API.
var trap = function () {
// create an Array from the arguments Object
var args = Array.prototype.slice.call(arguments);
// console.raw captures the raw args, without converting toString
console.raw.push(args);
var message = args.join(' ');
console.messages.push(message);
fallback(message);
};
// redefine console
if (typeof console === 'undefined') {
console = {
messages: [],
raw: [],
dump: function() { return console.messages.join('\n'); },
log: trap,
debug: trap,
info: trap,
warn: trap,
error: trap,
assert: trap,
clear: function() {
console.messages.length = 0;
console.raw.length = 0 ;
},
dir: trap,
dirxml: trap,
trace: trap,
group: trap,
groupCollapsed: trap,
groupEnd: trap,
time: trap,
timeEnd: trap,
timeStamp: trap,
profile: trap,
profileEnd: trap,
count: trap,
exception: trap,
table: trap
};
}
})(log.info);
我认为Log4Javascript支持IE8,所以这里有什么问题?感谢。
答案 0 :(得分:1)
log4javascript支持IE 8.问题是this
对log.info
的调用不正确,log
期望被调用为方法,因此引用this
为info
的值。我建议通过将logger对象传递给IIFE并调用其(function (log) {
var fallback = log ?
function() {
var args = Array.prototype.slice.call(arguments);
log.info.apply(log, args);
} :
function() { };
// function to trap most of the console functions from the FireBug Console API.
var trap = function () {
// create an Array from the arguments Object
var args = Array.prototype.slice.call(arguments);
// console.raw captures the raw args, without converting toString
console.raw.push(args);
var message = args.join(' ');
console.messages.push(message);
fallback(message);
};
// redefine console
if (typeof window.console === 'undefined') {
window.console = {
messages: [],
raw: [],
dump: function() { return console.messages.join('\n'); },
log: trap,
debug: trap,
info: trap,
warn: trap,
error: trap,
assert: trap,
clear: function() {
console.messages.length = 0;
console.raw.length = 0 ;
},
dir: trap,
dirxml: trap,
trace: trap,
group: trap,
groupCollapsed: trap,
groupEnd: trap,
time: trap,
timeEnd: trap,
timeStamp: trap,
profile: trap,
profileEnd: trap,
count: trap,
exception: trap,
table: trap
};
}
})(log);
方法来修复它:
<?php
include_once("php_includes/check_login_status.php");
if($user_ok != true || $log_username == ""){
header("location: http://burningchat.tk/home");
exit();
}
$_SESSION['user_id'] = md5(time());
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<style>
body{ margin: 0px; text-align: center; font-family: Arial; }
#pagetop{
position: fixed;
top: 0px;
width:100%;
height: 120px;
background: #FF5C26;
color: #FFF;
font-size: 23px;
padding-top: 50px;
transition: height 0.3s linear 0s, padding 0.3s linear 0s;
overflow:hidden;
}
#pagetop > #menu{
position: absolute;
bottom: 0px;
width:100%;
background: #FD4000;
height: 50px;
transition: height 0.3s linear 0s;
}
#wrapper{ margin-top: 230px;
}
#mainbody{
margin-top: 50px;
display:block;
}
</style>
<script>
var pagetop, menu, yPos;
function yScroll(){
pagetop = document.getElementById('pagetop');
menu = document.getElementById('menu');
yPos = window.pageYOffset;
if(yPos > 150){
pagetop.style.height = "36px";
pagetop.style.paddingTop = "8px";
menu.style.height = "0px";
} else {
pagetop.style.height = "120px";
pagetop.style.paddingTop = "50px";
menu.style.height = "50px";
}
}
window.addEventListener("scroll", yScroll);
</script>
</head>
<body>
<div id="pagetop">
The Gaming Hub
<div id="menu"><a href="http://burningchat.tk/home/user.php"><img src="images/home.png" alt="Chat" border="0" title="Go Back to Burning Chat"></a></div>
</div>
<div id="wrapper">
<h1><span style="font-family:tahoma,geneva,sans-serif;">Welcome to the Gaming Hub,</span></h1>
<p><span style="font-family:tahoma,geneva,sans-serif;">Whether the need is for something fun, or just to pass the time. Burning Chat's Gaming Hub allows a variety of fun activities, all for free.</span></p>
<hr width="50%">
<div id="mainbody">
<a href="http://burningchat.tk/home/chat/type/standard.html"><img src="images/standard.png" alt="Chat" border="0" title="Standard"></a>
<a href="http://burningchat.tk/home/chat/type/carbon.html"><img src="images/carbon.png" alt="Chat" border="0" title="Carbon"></a>
<a href="http://burningchat.tk/home/chat/type/gamer.html"><img src="images/gamer.png" alt="Chat" border="0" title="Gamer"></a>
</body>
</html>