-
Notifications
You must be signed in to change notification settings - Fork 379
Expand file tree
/
Copy pathconsole.js
More file actions
65 lines (51 loc) · 2.18 KB
/
console.js
File metadata and controls
65 lines (51 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
'use strict';
/*************************************************************************
## console global variable
ScriptCraft provides a `console` global variable with the followng methods...
* log()
* info()
* warn()
* error()
The ScriptCraft console methods work like the [Web API implementation][webcons].
### Example
console.log('Hello %s', 'world');
Basic variable substitution is supported (ScriptCraft's implementation
of console uses the Bukkit Plugin [Logger][lgr] or Canary Plugin [Logman][cmlgr] under the hood and
uses [java.lang.String.format()][strfmt] for variable
substitution. All output will be sent to the server console (not
in-game).
### Using string substitutions
ScriptCraft uses Java's [String.format()][strfmt] so any string substitution identifiers supported by
`java.lang.String.format()` are supported (e.g. %s , %d etc).
for (var i=0; i<5; i++) {
console.log("Hello, %s. You've called me %d times.", "Bob", i+1);
}
[lgr]: http://jd.bukkit.org/beta/apidocs/org/bukkit/plugin/PluginLogger.html
[cmlgr]: https://ci.visualillusionsent.net/job/CanaryLib/javadoc/net/canarymod/logger/Logman.html
[strfmt]: http://docs.oracle.com/javase/6/docs/api/java/lang/String.html#format(java.lang.String, java.lang.Object...)
[webcons]: https://developer.mozilla.org/en-US/docs/Web/API/console
***/
var util = require("util");
module.exports = function(logger){
function bukkitLog( level, restOfArgs ) {
logger['log(java.util.logging.Level,java.lang.String)'](
java.util.logging.Level[level],
util.format.apply(null, restOfArgs)
);
}
if (__plugin.canary){
return {
log: function( ) { logger.info( util.format.apply(arguments) ); },
info: function( ) { logger.info( util.format.apply(arguments) ); },
warn: function( ) { logger.warn( util.format.apply(arguments) ); },
error: function( ) { logger.error( util.format.apply(arguments) ); }
};
} else {
return {
log: function() { bukkitLog('INFO', arguments ); },
info: function() { bukkitLog('INFO', arguments ); },
warn: function( ) { bukkitLog('WARNING', arguments ); },
error: function( ) { bukkitLog('SEVERE', arguments ); }
};
}
};