├── .gitignore ├── Makefile ├── README.md ├── examples └── basic.js ├── index.js ├── lib ├── gen-nodejs │ ├── FacebookService.js │ ├── fb303_types.js │ ├── scribe.js │ └── scribe_types.js ├── logger.js ├── requestlog.js └── scribe.js ├── package.json ├── test ├── logger.test.js ├── requestlog.test.js └── scribe.test.js └── test_utils └── scribeserver.js /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | node_modules/ 3 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | TESTS = $(shell find . -name "*.test.js") 2 | 3 | test: 4 | @mocha -u tdd --globals "encoding" -t 8000 $(TESTS) -R spec 5 | 6 | 7 | .PHONY: test 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # node-scribe 2 | Scribe client for node.js. Project also includes a drop-in replacement (Logger) for the default console object. 3 | ## Installation 4 | $ npm install scribe 5 | ## Basic example 6 | Example of sending log entries to scribe server. 7 | 8 | var Scribe = require('scribe').Scribe; 9 | 10 | var scribe = new Scribe("localhost", 1234, {autoReconnect:true}); 11 | 12 | scribe.open(function(err){ 13 | 14 | if(err) { 15 | return console.log(err); 16 | } 17 | 18 | scribe.send("foocategory", "foomessage"); 19 | 20 | scribe.close(); 21 | 22 | }); 23 | 24 | ## autoReconnect = true 25 | If autoReconnect is set to true and connection fails, client will store log entries to queue and flush when connection has been re-established. 26 | 27 | ## Logger 28 | Logger is an drop-in replacement for the default console object. Each log entry contains the level, hostname, pid, caller (file and position) and the log message given as parameter. Values are separated by tabulators. 29 | 30 | ### Log levels 31 | Levels are defined by the function used or by hand when using the logMessage function.
32 | 0 : EMERG
33 | 1 : ALERT
34 | 2 : CRITICAL (critical)
35 | 3 : ERROR (error)
36 | 4 : WARN (warn)
37 | 5 : NOTICE
38 | 6 : INFO (info)
39 | 7 : DEBUG (debug, log)
40 | 41 | ### Example 42 | Example of using logger to replace node:s console object. 43 | 44 | var Scribe = require('scribe').Scribe; 45 | var Logger = require('scribe').Logger; 46 | 47 | var scribe = new Scribe("localhost", 1234, {autoReconnect:true}); 48 | var logger = new Logger(scribe, "foobar"); 49 | scribe.open(function(err){ 50 | 51 | if(err) { 52 | return console.log(err); 53 | } 54 | 55 | logger.log("foomessage"); 56 | 57 | logger.replaceConsole(); // replaces console with logger 58 | 59 | console.log("foobar"); 60 | 61 | logger.releaseConsole(); // reverts changes made by replaceConsole(); 62 | 63 | scribe.close(); 64 | 65 | }); 66 | 67 | # RequestLog 68 | 69 | Creates a middleware which will inject every req object with a log object. 70 | The log object contains an pseudo-unique id for each request in the req.log.id variable. 71 | 72 | In addition the req.log object contains console.log compatible logging functions: 73 | log, info, warn, error, critical. 74 | 75 | Each log message logged using those methods is passed into the custom writer() function, 76 | which the user must pass in the factory constructor. 77 | 78 | The writer takes the following arguments: 79 | function writer(level, request_id, line, message), where: 80 | - level is the numeric log level as defined in Logger: 81 | Logger.LOG_DEBUG = 7; 82 | Logger.LOG_INFO = 6; 83 | Logger.LOG_WARNING = 4; 84 | Logger.LOG_ERROR = 3; 85 | Logger.LOG_CRITICAL = 2; 86 | - request_id is the pseudo-randomly generated unique id for the request 87 | - line is a stacktrace line where the log message was generated, in form of "/path/to/file.js:line:character", eg "/path:tio:file.js:282:24" 88 | - message is a concatenated string of all the arguments passed to the log function 89 | 90 | Here's an example how we have used the writer to feed log lines to scribe: 91 | 92 | var hostname = require('os').hostname(); 93 | app.use(RequestLog.factory(function (level, id, line, msg) { 94 | var str = RequestLog.formatTimestamp(new Date()) + "\t" + RequestLog.levelNames[level] + "\t" + hostname + "\t" + process.pid + "\t" + line + "\t" + id + "\t" + msg; 95 | scribe.send("comet", str); 96 | })); 97 | 98 | Note that the req.log object is mostly compatible with the standard console object. 99 | This means that you can implement functions which accept an ubique 'logger' argument and you can log messages 100 | within these functions by calling for example logger.error("Something bad!"); Then you can pass the req.log 101 | object as the logger object, or simply pass 'console' from within your tests where you don't have access 102 | to a request related req object. 103 | 104 | Example: 105 | 106 | 107 | // Your function somewhere in your code, not directly related to any express request processing 108 | function someFunction(value, logger) { 109 | if (value == null) { 110 | logger.error("Value was null"); 111 | } 112 | } 113 | 114 | // Function which is directly related to express, for example a middleware 115 | function processRequest(req, res, next) { 116 | var value = req.query.value; 117 | someFunction(value, req.log); 118 | next(); 119 | } 120 | 121 | // You can test the someFunction in your TDD environment by passing console instead of req.log: 122 | test("my test", function() { 123 | someFunction("value", console); 124 | } 125 | 126 | ## License 127 | (The MIT License) 128 | 129 | Copyright(c) 2011 Applifier Ltd.
130 | 131 | Permission is hereby granted, free of charge, to any person obtaining 132 | a copy of this software and associated documentation files (the 133 | 'Software'), to deal in the Software without restriction, including 134 | without limitation the rights to use, copy, modify, merge, publish, 135 | distribute, sublicense, and/or sell copies of the Software, and to 136 | permit persons to whom the Software is furnished to do so, subject to 137 | the following conditions: 138 | 139 | The above copyright notice and this permission notice shall be 140 | included in all copies or substantial portions of the Software. 141 | 142 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, 143 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 144 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 145 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 146 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 147 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 148 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /examples/basic.js: -------------------------------------------------------------------------------- 1 | var Scribe = require('../lib/scribe').Scribe; 2 | 3 | var scribe = new Scribe("localhost", 3000, { autoReconnect : true }); 4 | 5 | 6 | scribe.open(function(err) { 7 | if (err) { 8 | console.log(err); 9 | return; 10 | } 11 | 12 | setInterval(function() { 13 | scribe.send("foo", "bar"); 14 | }, 150); 15 | }); 16 | 17 | scribe.on('connect', function(){ 18 | console.log("Client connected"); 19 | }); 20 | 21 | scribe.on('reconnecting', function(){ 22 | console.log("Client reconnecting"); 23 | }); 24 | 25 | scribe.on('error', function(err){ 26 | console.log("Error", err); 27 | }); 28 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | module.exports.Scribe = exports.Scribe = require('./lib/scribe.js').Scribe; 2 | module.exports.Logger = exports.Logger = require('./lib/logger.js').Logger; 3 | module.exports.RequestLog = exports.RequestLog = require('./lib/requestlog.js'); 4 | 5 | -------------------------------------------------------------------------------- /lib/gen-nodejs/FacebookService.js: -------------------------------------------------------------------------------- 1 | // 2 | // Autogenerated by Thrift 3 | // 4 | // DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | // 6 | var Thrift = require('thrift').Thrift; 7 | 8 | var ttypes = require('./fb303_types'); 9 | //HELPER FUNCTIONS AND STRUCTURES 10 | 11 | var FacebookService_getName_args = function(args) { 12 | } 13 | FacebookService_getName_args.prototype = {} 14 | FacebookService_getName_args.prototype.read = function(input) { 15 | var ret = input.readStructBegin() 16 | while (1) { 17 | var ret = input.readFieldBegin() 18 | var fname = ret.fname 19 | var ftype = ret.ftype 20 | var fid = ret.fid 21 | if (ftype == Thrift.Type.STOP) 22 | break 23 | switch (fid) { 24 | default: 25 | input.skip(ftype) 26 | } 27 | input.readFieldEnd() 28 | } 29 | input.readStructEnd() 30 | return 31 | } 32 | 33 | FacebookService_getName_args.prototype.write = function(output) { 34 | output.writeStructBegin('FacebookService_getName_args') 35 | output.writeFieldStop() 36 | output.writeStructEnd() 37 | return 38 | } 39 | 40 | var FacebookService_getName_result = function(args) { 41 | this.success = null 42 | if (args != null) { 43 | if (null != args.success) 44 | this.success = args.success 45 | } 46 | } 47 | FacebookService_getName_result.prototype = {} 48 | FacebookService_getName_result.prototype.read = function(input) { 49 | var ret = input.readStructBegin() 50 | while (1) { 51 | var ret = input.readFieldBegin() 52 | var fname = ret.fname 53 | var ftype = ret.ftype 54 | var fid = ret.fid 55 | if (ftype == Thrift.Type.STOP) 56 | break 57 | switch (fid) { 58 | case 0: 59 | if (ftype == Thrift.Type.STRING) { 60 | this.success = input.readString() 61 | } else { 62 | input.skip(ftype) 63 | } 64 | break 65 | default: 66 | input.skip(ftype) 67 | } 68 | input.readFieldEnd() 69 | } 70 | input.readStructEnd() 71 | return 72 | } 73 | 74 | FacebookService_getName_result.prototype.write = function(output) { 75 | output.writeStructBegin('FacebookService_getName_result') 76 | if (null != this.success) { 77 | output.writeFieldBegin('success', Thrift.Type.STRING, 0) 78 | output.writeString(this.success) 79 | output.writeFieldEnd() 80 | } 81 | output.writeFieldStop() 82 | output.writeStructEnd() 83 | return 84 | } 85 | 86 | var FacebookService_getVersion_args = function(args) { 87 | } 88 | FacebookService_getVersion_args.prototype = {} 89 | FacebookService_getVersion_args.prototype.read = function(input) { 90 | var ret = input.readStructBegin() 91 | while (1) { 92 | var ret = input.readFieldBegin() 93 | var fname = ret.fname 94 | var ftype = ret.ftype 95 | var fid = ret.fid 96 | if (ftype == Thrift.Type.STOP) 97 | break 98 | switch (fid) { 99 | default: 100 | input.skip(ftype) 101 | } 102 | input.readFieldEnd() 103 | } 104 | input.readStructEnd() 105 | return 106 | } 107 | 108 | FacebookService_getVersion_args.prototype.write = function(output) { 109 | output.writeStructBegin('FacebookService_getVersion_args') 110 | output.writeFieldStop() 111 | output.writeStructEnd() 112 | return 113 | } 114 | 115 | var FacebookService_getVersion_result = function(args) { 116 | this.success = null 117 | if (args != null) { 118 | if (null != args.success) 119 | this.success = args.success 120 | } 121 | } 122 | FacebookService_getVersion_result.prototype = {} 123 | FacebookService_getVersion_result.prototype.read = function(input) { 124 | var ret = input.readStructBegin() 125 | while (1) { 126 | var ret = input.readFieldBegin() 127 | var fname = ret.fname 128 | var ftype = ret.ftype 129 | var fid = ret.fid 130 | if (ftype == Thrift.Type.STOP) 131 | break 132 | switch (fid) { 133 | case 0: 134 | if (ftype == Thrift.Type.STRING) { 135 | this.success = input.readString() 136 | } else { 137 | input.skip(ftype) 138 | } 139 | break 140 | default: 141 | input.skip(ftype) 142 | } 143 | input.readFieldEnd() 144 | } 145 | input.readStructEnd() 146 | return 147 | } 148 | 149 | FacebookService_getVersion_result.prototype.write = function(output) { 150 | output.writeStructBegin('FacebookService_getVersion_result') 151 | if (null != this.success) { 152 | output.writeFieldBegin('success', Thrift.Type.STRING, 0) 153 | output.writeString(this.success) 154 | output.writeFieldEnd() 155 | } 156 | output.writeFieldStop() 157 | output.writeStructEnd() 158 | return 159 | } 160 | 161 | var FacebookService_getStatus_args = function(args) { 162 | } 163 | FacebookService_getStatus_args.prototype = {} 164 | FacebookService_getStatus_args.prototype.read = function(input) { 165 | var ret = input.readStructBegin() 166 | while (1) { 167 | var ret = input.readFieldBegin() 168 | var fname = ret.fname 169 | var ftype = ret.ftype 170 | var fid = ret.fid 171 | if (ftype == Thrift.Type.STOP) 172 | break 173 | switch (fid) { 174 | default: 175 | input.skip(ftype) 176 | } 177 | input.readFieldEnd() 178 | } 179 | input.readStructEnd() 180 | return 181 | } 182 | 183 | FacebookService_getStatus_args.prototype.write = function(output) { 184 | output.writeStructBegin('FacebookService_getStatus_args') 185 | output.writeFieldStop() 186 | output.writeStructEnd() 187 | return 188 | } 189 | 190 | var FacebookService_getStatus_result = function(args) { 191 | this.success = null 192 | if (args != null) { 193 | if (null != args.success) 194 | this.success = args.success 195 | } 196 | } 197 | FacebookService_getStatus_result.prototype = {} 198 | FacebookService_getStatus_result.prototype.read = function(input) { 199 | var ret = input.readStructBegin() 200 | while (1) { 201 | var ret = input.readFieldBegin() 202 | var fname = ret.fname 203 | var ftype = ret.ftype 204 | var fid = ret.fid 205 | if (ftype == Thrift.Type.STOP) 206 | break 207 | switch (fid) { 208 | case 0: 209 | if (ftype == Thrift.Type.I32) { 210 | this.success = input.readI32() 211 | } else { 212 | input.skip(ftype) 213 | } 214 | break 215 | default: 216 | input.skip(ftype) 217 | } 218 | input.readFieldEnd() 219 | } 220 | input.readStructEnd() 221 | return 222 | } 223 | 224 | FacebookService_getStatus_result.prototype.write = function(output) { 225 | output.writeStructBegin('FacebookService_getStatus_result') 226 | if (null != this.success) { 227 | output.writeFieldBegin('success', Thrift.Type.I32, 0) 228 | output.writeI32(this.success) 229 | output.writeFieldEnd() 230 | } 231 | output.writeFieldStop() 232 | output.writeStructEnd() 233 | return 234 | } 235 | 236 | var FacebookService_getStatusDetails_args = function(args) { 237 | } 238 | FacebookService_getStatusDetails_args.prototype = {} 239 | FacebookService_getStatusDetails_args.prototype.read = function(input) { 240 | var ret = input.readStructBegin() 241 | while (1) { 242 | var ret = input.readFieldBegin() 243 | var fname = ret.fname 244 | var ftype = ret.ftype 245 | var fid = ret.fid 246 | if (ftype == Thrift.Type.STOP) 247 | break 248 | switch (fid) { 249 | default: 250 | input.skip(ftype) 251 | } 252 | input.readFieldEnd() 253 | } 254 | input.readStructEnd() 255 | return 256 | } 257 | 258 | FacebookService_getStatusDetails_args.prototype.write = function(output) { 259 | output.writeStructBegin('FacebookService_getStatusDetails_args') 260 | output.writeFieldStop() 261 | output.writeStructEnd() 262 | return 263 | } 264 | 265 | var FacebookService_getStatusDetails_result = function(args) { 266 | this.success = null 267 | if (args != null) { 268 | if (null != args.success) 269 | this.success = args.success 270 | } 271 | } 272 | FacebookService_getStatusDetails_result.prototype = {} 273 | FacebookService_getStatusDetails_result.prototype.read = function(input) { 274 | var ret = input.readStructBegin() 275 | while (1) { 276 | var ret = input.readFieldBegin() 277 | var fname = ret.fname 278 | var ftype = ret.ftype 279 | var fid = ret.fid 280 | if (ftype == Thrift.Type.STOP) 281 | break 282 | switch (fid) { 283 | case 0: 284 | if (ftype == Thrift.Type.STRING) { 285 | this.success = input.readString() 286 | } else { 287 | input.skip(ftype) 288 | } 289 | break 290 | default: 291 | input.skip(ftype) 292 | } 293 | input.readFieldEnd() 294 | } 295 | input.readStructEnd() 296 | return 297 | } 298 | 299 | FacebookService_getStatusDetails_result.prototype.write = function(output) { 300 | output.writeStructBegin('FacebookService_getStatusDetails_result') 301 | if (null != this.success) { 302 | output.writeFieldBegin('success', Thrift.Type.STRING, 0) 303 | output.writeString(this.success) 304 | output.writeFieldEnd() 305 | } 306 | output.writeFieldStop() 307 | output.writeStructEnd() 308 | return 309 | } 310 | 311 | var FacebookService_getCounters_args = function(args) { 312 | } 313 | FacebookService_getCounters_args.prototype = {} 314 | FacebookService_getCounters_args.prototype.read = function(input) { 315 | var ret = input.readStructBegin() 316 | while (1) { 317 | var ret = input.readFieldBegin() 318 | var fname = ret.fname 319 | var ftype = ret.ftype 320 | var fid = ret.fid 321 | if (ftype == Thrift.Type.STOP) 322 | break 323 | switch (fid) { 324 | default: 325 | input.skip(ftype) 326 | } 327 | input.readFieldEnd() 328 | } 329 | input.readStructEnd() 330 | return 331 | } 332 | 333 | FacebookService_getCounters_args.prototype.write = function(output) { 334 | output.writeStructBegin('FacebookService_getCounters_args') 335 | output.writeFieldStop() 336 | output.writeStructEnd() 337 | return 338 | } 339 | 340 | var FacebookService_getCounters_result = function(args) { 341 | this.success = null 342 | if (args != null) { 343 | if (null != args.success) 344 | this.success = args.success 345 | } 346 | } 347 | FacebookService_getCounters_result.prototype = {} 348 | FacebookService_getCounters_result.prototype.read = function(input) { 349 | var ret = input.readStructBegin() 350 | while (1) { 351 | var ret = input.readFieldBegin() 352 | var fname = ret.fname 353 | var ftype = ret.ftype 354 | var fid = ret.fid 355 | if (ftype == Thrift.Type.STOP) 356 | break 357 | switch (fid) { 358 | case 0: 359 | if (ftype == Thrift.Type.MAP) { 360 | { 361 | var _size0 = 0 362 | var rtmp3 363 | this.success = {} 364 | var _ktype1 = 0 365 | var _vtype2 = 0 366 | rtmp3 = input.readMapBegin() 367 | _ktype1 = rtmp3.ktype 368 | _vtype2 = rtmp3.vtype 369 | _size0 = rtmp3.size 370 | for (var _i4 = 0; _i4 < _size0; ++_i4) { 371 | key5 = null 372 | val6 = null 373 | key5 = input.readString() 374 | val6 = input.readI64() 375 | this.success[key5] = val6 376 | } 377 | input.readMapEnd() 378 | } 379 | } else { 380 | input.skip(ftype) 381 | } 382 | break 383 | default: 384 | input.skip(ftype) 385 | } 386 | input.readFieldEnd() 387 | } 388 | input.readStructEnd() 389 | return 390 | } 391 | 392 | FacebookService_getCounters_result.prototype.write = function(output) { 393 | output.writeStructBegin('FacebookService_getCounters_result') 394 | if (null != this.success) { 395 | output.writeFieldBegin('success', Thrift.Type.MAP, 0) 396 | { 397 | output.writeMapBegin(Thrift.Type.STRING, Thrift.Type.I64, Thrift.objectLength(this.success)) 398 | { 399 | for (var kiter7 in this.success) { 400 | if (this.success.hasOwnProperty(kiter7)) { 401 | var viter8 = this.success[kiter7] 402 | output.writeString(kiter7) 403 | output.writeI64(viter8) 404 | } 405 | } 406 | } 407 | output.writeMapEnd() 408 | } 409 | output.writeFieldEnd() 410 | } 411 | output.writeFieldStop() 412 | output.writeStructEnd() 413 | return 414 | } 415 | 416 | var FacebookService_getCounter_args = function(args) { 417 | this.key = null 418 | if (args != null) { 419 | if (null != args.key) 420 | this.key = args.key 421 | } 422 | } 423 | FacebookService_getCounter_args.prototype = {} 424 | FacebookService_getCounter_args.prototype.read = function(input) { 425 | var ret = input.readStructBegin() 426 | while (1) { 427 | var ret = input.readFieldBegin() 428 | var fname = ret.fname 429 | var ftype = ret.ftype 430 | var fid = ret.fid 431 | if (ftype == Thrift.Type.STOP) 432 | break 433 | switch (fid) { 434 | case 1: 435 | if (ftype == Thrift.Type.STRING) { 436 | this.key = input.readString() 437 | } else { 438 | input.skip(ftype) 439 | } 440 | break 441 | default: 442 | input.skip(ftype) 443 | } 444 | input.readFieldEnd() 445 | } 446 | input.readStructEnd() 447 | return 448 | } 449 | 450 | FacebookService_getCounter_args.prototype.write = function(output) { 451 | output.writeStructBegin('FacebookService_getCounter_args') 452 | if (null != this.key) { 453 | output.writeFieldBegin('key', Thrift.Type.STRING, 1) 454 | output.writeString(this.key) 455 | output.writeFieldEnd() 456 | } 457 | output.writeFieldStop() 458 | output.writeStructEnd() 459 | return 460 | } 461 | 462 | var FacebookService_getCounter_result = function(args) { 463 | this.success = null 464 | if (args != null) { 465 | if (null != args.success) 466 | this.success = args.success 467 | } 468 | } 469 | FacebookService_getCounter_result.prototype = {} 470 | FacebookService_getCounter_result.prototype.read = function(input) { 471 | var ret = input.readStructBegin() 472 | while (1) { 473 | var ret = input.readFieldBegin() 474 | var fname = ret.fname 475 | var ftype = ret.ftype 476 | var fid = ret.fid 477 | if (ftype == Thrift.Type.STOP) 478 | break 479 | switch (fid) { 480 | case 0: 481 | if (ftype == Thrift.Type.I64) { 482 | this.success = input.readI64() 483 | } else { 484 | input.skip(ftype) 485 | } 486 | break 487 | default: 488 | input.skip(ftype) 489 | } 490 | input.readFieldEnd() 491 | } 492 | input.readStructEnd() 493 | return 494 | } 495 | 496 | FacebookService_getCounter_result.prototype.write = function(output) { 497 | output.writeStructBegin('FacebookService_getCounter_result') 498 | if (null != this.success) { 499 | output.writeFieldBegin('success', Thrift.Type.I64, 0) 500 | output.writeI64(this.success) 501 | output.writeFieldEnd() 502 | } 503 | output.writeFieldStop() 504 | output.writeStructEnd() 505 | return 506 | } 507 | 508 | var FacebookService_setOption_args = function(args) { 509 | this.key = null 510 | this.value = null 511 | if (args != null) { 512 | if (null != args.key) 513 | this.key = args.key 514 | if (null != args.value) 515 | this.value = args.value 516 | } 517 | } 518 | FacebookService_setOption_args.prototype = {} 519 | FacebookService_setOption_args.prototype.read = function(input) { 520 | var ret = input.readStructBegin() 521 | while (1) { 522 | var ret = input.readFieldBegin() 523 | var fname = ret.fname 524 | var ftype = ret.ftype 525 | var fid = ret.fid 526 | if (ftype == Thrift.Type.STOP) 527 | break 528 | switch (fid) { 529 | case 1: 530 | if (ftype == Thrift.Type.STRING) { 531 | this.key = input.readString() 532 | } else { 533 | input.skip(ftype) 534 | } 535 | break 536 | case 2: 537 | if (ftype == Thrift.Type.STRING) { 538 | this.value = input.readString() 539 | } else { 540 | input.skip(ftype) 541 | } 542 | break 543 | default: 544 | input.skip(ftype) 545 | } 546 | input.readFieldEnd() 547 | } 548 | input.readStructEnd() 549 | return 550 | } 551 | 552 | FacebookService_setOption_args.prototype.write = function(output) { 553 | output.writeStructBegin('FacebookService_setOption_args') 554 | if (null != this.key) { 555 | output.writeFieldBegin('key', Thrift.Type.STRING, 1) 556 | output.writeString(this.key) 557 | output.writeFieldEnd() 558 | } 559 | if (null != this.value) { 560 | output.writeFieldBegin('value', Thrift.Type.STRING, 2) 561 | output.writeString(this.value) 562 | output.writeFieldEnd() 563 | } 564 | output.writeFieldStop() 565 | output.writeStructEnd() 566 | return 567 | } 568 | 569 | var FacebookService_setOption_result = function(args) { 570 | } 571 | FacebookService_setOption_result.prototype = {} 572 | FacebookService_setOption_result.prototype.read = function(input) { 573 | var ret = input.readStructBegin() 574 | while (1) { 575 | var ret = input.readFieldBegin() 576 | var fname = ret.fname 577 | var ftype = ret.ftype 578 | var fid = ret.fid 579 | if (ftype == Thrift.Type.STOP) 580 | break 581 | switch (fid) { 582 | default: 583 | input.skip(ftype) 584 | } 585 | input.readFieldEnd() 586 | } 587 | input.readStructEnd() 588 | return 589 | } 590 | 591 | FacebookService_setOption_result.prototype.write = function(output) { 592 | output.writeStructBegin('FacebookService_setOption_result') 593 | output.writeFieldStop() 594 | output.writeStructEnd() 595 | return 596 | } 597 | 598 | var FacebookService_getOption_args = function(args) { 599 | this.key = null 600 | if (args != null) { 601 | if (null != args.key) 602 | this.key = args.key 603 | } 604 | } 605 | FacebookService_getOption_args.prototype = {} 606 | FacebookService_getOption_args.prototype.read = function(input) { 607 | var ret = input.readStructBegin() 608 | while (1) { 609 | var ret = input.readFieldBegin() 610 | var fname = ret.fname 611 | var ftype = ret.ftype 612 | var fid = ret.fid 613 | if (ftype == Thrift.Type.STOP) 614 | break 615 | switch (fid) { 616 | case 1: 617 | if (ftype == Thrift.Type.STRING) { 618 | this.key = input.readString() 619 | } else { 620 | input.skip(ftype) 621 | } 622 | break 623 | default: 624 | input.skip(ftype) 625 | } 626 | input.readFieldEnd() 627 | } 628 | input.readStructEnd() 629 | return 630 | } 631 | 632 | FacebookService_getOption_args.prototype.write = function(output) { 633 | output.writeStructBegin('FacebookService_getOption_args') 634 | if (null != this.key) { 635 | output.writeFieldBegin('key', Thrift.Type.STRING, 1) 636 | output.writeString(this.key) 637 | output.writeFieldEnd() 638 | } 639 | output.writeFieldStop() 640 | output.writeStructEnd() 641 | return 642 | } 643 | 644 | var FacebookService_getOption_result = function(args) { 645 | this.success = null 646 | if (args != null) { 647 | if (null != args.success) 648 | this.success = args.success 649 | } 650 | } 651 | FacebookService_getOption_result.prototype = {} 652 | FacebookService_getOption_result.prototype.read = function(input) { 653 | var ret = input.readStructBegin() 654 | while (1) { 655 | var ret = input.readFieldBegin() 656 | var fname = ret.fname 657 | var ftype = ret.ftype 658 | var fid = ret.fid 659 | if (ftype == Thrift.Type.STOP) 660 | break 661 | switch (fid) { 662 | case 0: 663 | if (ftype == Thrift.Type.STRING) { 664 | this.success = input.readString() 665 | } else { 666 | input.skip(ftype) 667 | } 668 | break 669 | default: 670 | input.skip(ftype) 671 | } 672 | input.readFieldEnd() 673 | } 674 | input.readStructEnd() 675 | return 676 | } 677 | 678 | FacebookService_getOption_result.prototype.write = function(output) { 679 | output.writeStructBegin('FacebookService_getOption_result') 680 | if (null != this.success) { 681 | output.writeFieldBegin('success', Thrift.Type.STRING, 0) 682 | output.writeString(this.success) 683 | output.writeFieldEnd() 684 | } 685 | output.writeFieldStop() 686 | output.writeStructEnd() 687 | return 688 | } 689 | 690 | var FacebookService_getOptions_args = function(args) { 691 | } 692 | FacebookService_getOptions_args.prototype = {} 693 | FacebookService_getOptions_args.prototype.read = function(input) { 694 | var ret = input.readStructBegin() 695 | while (1) { 696 | var ret = input.readFieldBegin() 697 | var fname = ret.fname 698 | var ftype = ret.ftype 699 | var fid = ret.fid 700 | if (ftype == Thrift.Type.STOP) 701 | break 702 | switch (fid) { 703 | default: 704 | input.skip(ftype) 705 | } 706 | input.readFieldEnd() 707 | } 708 | input.readStructEnd() 709 | return 710 | } 711 | 712 | FacebookService_getOptions_args.prototype.write = function(output) { 713 | output.writeStructBegin('FacebookService_getOptions_args') 714 | output.writeFieldStop() 715 | output.writeStructEnd() 716 | return 717 | } 718 | 719 | var FacebookService_getOptions_result = function(args) { 720 | this.success = null 721 | if (args != null) { 722 | if (null != args.success) 723 | this.success = args.success 724 | } 725 | } 726 | FacebookService_getOptions_result.prototype = {} 727 | FacebookService_getOptions_result.prototype.read = function(input) { 728 | var ret = input.readStructBegin() 729 | while (1) { 730 | var ret = input.readFieldBegin() 731 | var fname = ret.fname 732 | var ftype = ret.ftype 733 | var fid = ret.fid 734 | if (ftype == Thrift.Type.STOP) 735 | break 736 | switch (fid) { 737 | case 0: 738 | if (ftype == Thrift.Type.MAP) { 739 | { 740 | var _size9 = 0 741 | var rtmp3 742 | this.success = {} 743 | var _ktype10 = 0 744 | var _vtype11 = 0 745 | rtmp3 = input.readMapBegin() 746 | _ktype10 = rtmp3.ktype 747 | _vtype11 = rtmp3.vtype 748 | _size9 = rtmp3.size 749 | for (var _i13 = 0; _i13 < _size9; ++_i13) { 750 | key14 = null 751 | val15 = null 752 | key14 = input.readString() 753 | val15 = input.readString() 754 | this.success[key14] = val15 755 | } 756 | input.readMapEnd() 757 | } 758 | } else { 759 | input.skip(ftype) 760 | } 761 | break 762 | default: 763 | input.skip(ftype) 764 | } 765 | input.readFieldEnd() 766 | } 767 | input.readStructEnd() 768 | return 769 | } 770 | 771 | FacebookService_getOptions_result.prototype.write = function(output) { 772 | output.writeStructBegin('FacebookService_getOptions_result') 773 | if (null != this.success) { 774 | output.writeFieldBegin('success', Thrift.Type.MAP, 0) 775 | { 776 | output.writeMapBegin(Thrift.Type.STRING, Thrift.Type.STRING, Thrift.objectLength(this.success)) 777 | { 778 | for (var kiter16 in this.success) { 779 | if (this.success.hasOwnProperty(kiter16)) { 780 | var viter17 = this.success[kiter16] 781 | output.writeString(kiter16) 782 | output.writeString(viter17) 783 | } 784 | } 785 | } 786 | output.writeMapEnd() 787 | } 788 | output.writeFieldEnd() 789 | } 790 | output.writeFieldStop() 791 | output.writeStructEnd() 792 | return 793 | } 794 | 795 | var FacebookService_getCpuProfile_args = function(args) { 796 | this.profileDurationInSec = null 797 | if (args != null) { 798 | if (null != args.profileDurationInSec) 799 | this.profileDurationInSec = args.profileDurationInSec 800 | } 801 | } 802 | FacebookService_getCpuProfile_args.prototype = {} 803 | FacebookService_getCpuProfile_args.prototype.read = function(input) { 804 | var ret = input.readStructBegin() 805 | while (1) { 806 | var ret = input.readFieldBegin() 807 | var fname = ret.fname 808 | var ftype = ret.ftype 809 | var fid = ret.fid 810 | if (ftype == Thrift.Type.STOP) 811 | break 812 | switch (fid) { 813 | case 1: 814 | if (ftype == Thrift.Type.I32) { 815 | this.profileDurationInSec = input.readI32() 816 | } else { 817 | input.skip(ftype) 818 | } 819 | break 820 | default: 821 | input.skip(ftype) 822 | } 823 | input.readFieldEnd() 824 | } 825 | input.readStructEnd() 826 | return 827 | } 828 | 829 | FacebookService_getCpuProfile_args.prototype.write = function(output) { 830 | output.writeStructBegin('FacebookService_getCpuProfile_args') 831 | if (null != this.profileDurationInSec) { 832 | output.writeFieldBegin('profileDurationInSec', Thrift.Type.I32, 1) 833 | output.writeI32(this.profileDurationInSec) 834 | output.writeFieldEnd() 835 | } 836 | output.writeFieldStop() 837 | output.writeStructEnd() 838 | return 839 | } 840 | 841 | var FacebookService_getCpuProfile_result = function(args) { 842 | this.success = null 843 | if (args != null) { 844 | if (null != args.success) 845 | this.success = args.success 846 | } 847 | } 848 | FacebookService_getCpuProfile_result.prototype = {} 849 | FacebookService_getCpuProfile_result.prototype.read = function(input) { 850 | var ret = input.readStructBegin() 851 | while (1) { 852 | var ret = input.readFieldBegin() 853 | var fname = ret.fname 854 | var ftype = ret.ftype 855 | var fid = ret.fid 856 | if (ftype == Thrift.Type.STOP) 857 | break 858 | switch (fid) { 859 | case 0: 860 | if (ftype == Thrift.Type.STRING) { 861 | this.success = input.readString() 862 | } else { 863 | input.skip(ftype) 864 | } 865 | break 866 | default: 867 | input.skip(ftype) 868 | } 869 | input.readFieldEnd() 870 | } 871 | input.readStructEnd() 872 | return 873 | } 874 | 875 | FacebookService_getCpuProfile_result.prototype.write = function(output) { 876 | output.writeStructBegin('FacebookService_getCpuProfile_result') 877 | if (null != this.success) { 878 | output.writeFieldBegin('success', Thrift.Type.STRING, 0) 879 | output.writeString(this.success) 880 | output.writeFieldEnd() 881 | } 882 | output.writeFieldStop() 883 | output.writeStructEnd() 884 | return 885 | } 886 | 887 | var FacebookService_aliveSince_args = function(args) { 888 | } 889 | FacebookService_aliveSince_args.prototype = {} 890 | FacebookService_aliveSince_args.prototype.read = function(input) { 891 | var ret = input.readStructBegin() 892 | while (1) { 893 | var ret = input.readFieldBegin() 894 | var fname = ret.fname 895 | var ftype = ret.ftype 896 | var fid = ret.fid 897 | if (ftype == Thrift.Type.STOP) 898 | break 899 | switch (fid) { 900 | default: 901 | input.skip(ftype) 902 | } 903 | input.readFieldEnd() 904 | } 905 | input.readStructEnd() 906 | return 907 | } 908 | 909 | FacebookService_aliveSince_args.prototype.write = function(output) { 910 | output.writeStructBegin('FacebookService_aliveSince_args') 911 | output.writeFieldStop() 912 | output.writeStructEnd() 913 | return 914 | } 915 | 916 | var FacebookService_aliveSince_result = function(args) { 917 | this.success = null 918 | if (args != null) { 919 | if (null != args.success) 920 | this.success = args.success 921 | } 922 | } 923 | FacebookService_aliveSince_result.prototype = {} 924 | FacebookService_aliveSince_result.prototype.read = function(input) { 925 | var ret = input.readStructBegin() 926 | while (1) { 927 | var ret = input.readFieldBegin() 928 | var fname = ret.fname 929 | var ftype = ret.ftype 930 | var fid = ret.fid 931 | if (ftype == Thrift.Type.STOP) 932 | break 933 | switch (fid) { 934 | case 0: 935 | if (ftype == Thrift.Type.I64) { 936 | this.success = input.readI64() 937 | } else { 938 | input.skip(ftype) 939 | } 940 | break 941 | default: 942 | input.skip(ftype) 943 | } 944 | input.readFieldEnd() 945 | } 946 | input.readStructEnd() 947 | return 948 | } 949 | 950 | FacebookService_aliveSince_result.prototype.write = function(output) { 951 | output.writeStructBegin('FacebookService_aliveSince_result') 952 | if (null != this.success) { 953 | output.writeFieldBegin('success', Thrift.Type.I64, 0) 954 | output.writeI64(this.success) 955 | output.writeFieldEnd() 956 | } 957 | output.writeFieldStop() 958 | output.writeStructEnd() 959 | return 960 | } 961 | 962 | var FacebookService_reinitialize_args = function(args) { 963 | } 964 | FacebookService_reinitialize_args.prototype = {} 965 | FacebookService_reinitialize_args.prototype.read = function(input) { 966 | var ret = input.readStructBegin() 967 | while (1) { 968 | var ret = input.readFieldBegin() 969 | var fname = ret.fname 970 | var ftype = ret.ftype 971 | var fid = ret.fid 972 | if (ftype == Thrift.Type.STOP) 973 | break 974 | switch (fid) { 975 | default: 976 | input.skip(ftype) 977 | } 978 | input.readFieldEnd() 979 | } 980 | input.readStructEnd() 981 | return 982 | } 983 | 984 | FacebookService_reinitialize_args.prototype.write = function(output) { 985 | output.writeStructBegin('FacebookService_reinitialize_args') 986 | output.writeFieldStop() 987 | output.writeStructEnd() 988 | return 989 | } 990 | 991 | var FacebookService_reinitialize_result = function(args) { 992 | } 993 | FacebookService_reinitialize_result.prototype = {} 994 | FacebookService_reinitialize_result.prototype.read = function(input) { 995 | var ret = input.readStructBegin() 996 | while (1) { 997 | var ret = input.readFieldBegin() 998 | var fname = ret.fname 999 | var ftype = ret.ftype 1000 | var fid = ret.fid 1001 | if (ftype == Thrift.Type.STOP) 1002 | break 1003 | switch (fid) { 1004 | default: 1005 | input.skip(ftype) 1006 | } 1007 | input.readFieldEnd() 1008 | } 1009 | input.readStructEnd() 1010 | return 1011 | } 1012 | 1013 | FacebookService_reinitialize_result.prototype.write = function(output) { 1014 | output.writeStructBegin('FacebookService_reinitialize_result') 1015 | output.writeFieldStop() 1016 | output.writeStructEnd() 1017 | return 1018 | } 1019 | 1020 | var FacebookService_shutdown_args = function(args) { 1021 | } 1022 | FacebookService_shutdown_args.prototype = {} 1023 | FacebookService_shutdown_args.prototype.read = function(input) { 1024 | var ret = input.readStructBegin() 1025 | while (1) { 1026 | var ret = input.readFieldBegin() 1027 | var fname = ret.fname 1028 | var ftype = ret.ftype 1029 | var fid = ret.fid 1030 | if (ftype == Thrift.Type.STOP) 1031 | break 1032 | switch (fid) { 1033 | default: 1034 | input.skip(ftype) 1035 | } 1036 | input.readFieldEnd() 1037 | } 1038 | input.readStructEnd() 1039 | return 1040 | } 1041 | 1042 | FacebookService_shutdown_args.prototype.write = function(output) { 1043 | output.writeStructBegin('FacebookService_shutdown_args') 1044 | output.writeFieldStop() 1045 | output.writeStructEnd() 1046 | return 1047 | } 1048 | 1049 | var FacebookService_shutdown_result = function(args) { 1050 | } 1051 | FacebookService_shutdown_result.prototype = {} 1052 | FacebookService_shutdown_result.prototype.read = function(input) { 1053 | var ret = input.readStructBegin() 1054 | while (1) { 1055 | var ret = input.readFieldBegin() 1056 | var fname = ret.fname 1057 | var ftype = ret.ftype 1058 | var fid = ret.fid 1059 | if (ftype == Thrift.Type.STOP) 1060 | break 1061 | switch (fid) { 1062 | default: 1063 | input.skip(ftype) 1064 | } 1065 | input.readFieldEnd() 1066 | } 1067 | input.readStructEnd() 1068 | return 1069 | } 1070 | 1071 | FacebookService_shutdown_result.prototype.write = function(output) { 1072 | output.writeStructBegin('FacebookService_shutdown_result') 1073 | output.writeFieldStop() 1074 | output.writeStructEnd() 1075 | return 1076 | } 1077 | 1078 | var FacebookServiceClient = exports.Client = function(output, pClass) { 1079 | this.output = output; 1080 | this.pClass = pClass; 1081 | this.seqid = 0; 1082 | this._reqs = {} 1083 | } 1084 | FacebookServiceClient.prototype = {} 1085 | FacebookServiceClient.prototype.getName = function(callback) { 1086 | this.seqid += 1; 1087 | this._reqs[this.seqid] = callback; 1088 | this.send_getName() 1089 | } 1090 | 1091 | FacebookServiceClient.prototype.send_getName = function() { 1092 | var output = new this.pClass(this.output); 1093 | output.writeMessageBegin('getName', Thrift.MessageType.CALL, this.seqid) 1094 | var args = new FacebookService_getName_args() 1095 | args.write(output) 1096 | output.writeMessageEnd() 1097 | return this.output.flush() 1098 | } 1099 | 1100 | FacebookServiceClient.prototype.recv_getName = function(input, mtype, rseqid) { 1101 | var callback = this._reqs[rseqid] || function() { 1102 | }; 1103 | delete this._reqs[rseqid]; 1104 | if (mtype == Thrift.MessageType.EXCEPTION) { 1105 | var x = new Thrift.TApplicationException() 1106 | x.read(input) 1107 | input.readMessageEnd() 1108 | return callback(x); 1109 | } 1110 | var result = new FacebookService_getName_result() 1111 | result.read(input) 1112 | input.readMessageEnd() 1113 | 1114 | if (null != result.success) { 1115 | return callback(null, result.success); 1116 | } 1117 | return callback("getName failed: unknown result"); 1118 | } 1119 | FacebookServiceClient.prototype.getVersion = function(callback) { 1120 | this.seqid += 1; 1121 | this._reqs[this.seqid] = callback; 1122 | this.send_getVersion() 1123 | } 1124 | 1125 | FacebookServiceClient.prototype.send_getVersion = function() { 1126 | var output = new this.pClass(this.output); 1127 | output.writeMessageBegin('getVersion', Thrift.MessageType.CALL, this.seqid) 1128 | var args = new FacebookService_getVersion_args() 1129 | args.write(output) 1130 | output.writeMessageEnd() 1131 | return this.output.flush() 1132 | } 1133 | 1134 | FacebookServiceClient.prototype.recv_getVersion = function(input, mtype, rseqid) { 1135 | var callback = this._reqs[rseqid] || function() { 1136 | }; 1137 | delete this._reqs[rseqid]; 1138 | if (mtype == Thrift.MessageType.EXCEPTION) { 1139 | var x = new Thrift.TApplicationException() 1140 | x.read(input) 1141 | input.readMessageEnd() 1142 | return callback(x); 1143 | } 1144 | var result = new FacebookService_getVersion_result() 1145 | result.read(input) 1146 | input.readMessageEnd() 1147 | 1148 | if (null != result.success) { 1149 | return callback(null, result.success); 1150 | } 1151 | return callback("getVersion failed: unknown result"); 1152 | } 1153 | FacebookServiceClient.prototype.getStatus = function(callback) { 1154 | this.seqid += 1; 1155 | this._reqs[this.seqid] = callback; 1156 | this.send_getStatus() 1157 | } 1158 | 1159 | FacebookServiceClient.prototype.send_getStatus = function() { 1160 | var output = new this.pClass(this.output); 1161 | output.writeMessageBegin('getStatus', Thrift.MessageType.CALL, this.seqid) 1162 | var args = new FacebookService_getStatus_args() 1163 | args.write(output) 1164 | output.writeMessageEnd() 1165 | return this.output.flush() 1166 | } 1167 | 1168 | FacebookServiceClient.prototype.recv_getStatus = function(input, mtype, rseqid) { 1169 | var callback = this._reqs[rseqid] || function() { 1170 | }; 1171 | delete this._reqs[rseqid]; 1172 | if (mtype == Thrift.MessageType.EXCEPTION) { 1173 | var x = new Thrift.TApplicationException() 1174 | x.read(input) 1175 | input.readMessageEnd() 1176 | return callback(x); 1177 | } 1178 | var result = new FacebookService_getStatus_result() 1179 | result.read(input) 1180 | input.readMessageEnd() 1181 | 1182 | if (null != result.success) { 1183 | return callback(null, result.success); 1184 | } 1185 | return callback("getStatus failed: unknown result"); 1186 | } 1187 | FacebookServiceClient.prototype.getStatusDetails = function(callback) { 1188 | this.seqid += 1; 1189 | this._reqs[this.seqid] = callback; 1190 | this.send_getStatusDetails() 1191 | } 1192 | 1193 | FacebookServiceClient.prototype.send_getStatusDetails = function() { 1194 | var output = new this.pClass(this.output); 1195 | output.writeMessageBegin('getStatusDetails', Thrift.MessageType.CALL, this.seqid) 1196 | var args = new FacebookService_getStatusDetails_args() 1197 | args.write(output) 1198 | output.writeMessageEnd() 1199 | return this.output.flush() 1200 | } 1201 | 1202 | FacebookServiceClient.prototype.recv_getStatusDetails = function(input, mtype, rseqid) { 1203 | var callback = this._reqs[rseqid] || function() { 1204 | }; 1205 | delete this._reqs[rseqid]; 1206 | if (mtype == Thrift.MessageType.EXCEPTION) { 1207 | var x = new Thrift.TApplicationException() 1208 | x.read(input) 1209 | input.readMessageEnd() 1210 | return callback(x); 1211 | } 1212 | var result = new FacebookService_getStatusDetails_result() 1213 | result.read(input) 1214 | input.readMessageEnd() 1215 | 1216 | if (null != result.success) { 1217 | return callback(null, result.success); 1218 | } 1219 | return callback("getStatusDetails failed: unknown result"); 1220 | } 1221 | FacebookServiceClient.prototype.getCounters = function(callback) { 1222 | this.seqid += 1; 1223 | this._reqs[this.seqid] = callback; 1224 | this.send_getCounters() 1225 | } 1226 | 1227 | FacebookServiceClient.prototype.send_getCounters = function() { 1228 | var output = new this.pClass(this.output); 1229 | output.writeMessageBegin('getCounters', Thrift.MessageType.CALL, this.seqid) 1230 | var args = new FacebookService_getCounters_args() 1231 | args.write(output) 1232 | output.writeMessageEnd() 1233 | return this.output.flush() 1234 | } 1235 | 1236 | FacebookServiceClient.prototype.recv_getCounters = function(input, mtype, rseqid) { 1237 | var callback = this._reqs[rseqid] || function() { 1238 | }; 1239 | delete this._reqs[rseqid]; 1240 | if (mtype == Thrift.MessageType.EXCEPTION) { 1241 | var x = new Thrift.TApplicationException() 1242 | x.read(input) 1243 | input.readMessageEnd() 1244 | return callback(x); 1245 | } 1246 | var result = new FacebookService_getCounters_result() 1247 | result.read(input) 1248 | input.readMessageEnd() 1249 | 1250 | if (null != result.success) { 1251 | return callback(null, result.success); 1252 | } 1253 | return callback("getCounters failed: unknown result"); 1254 | } 1255 | FacebookServiceClient.prototype.getCounter = function(key, callback) { 1256 | this.seqid += 1; 1257 | this._reqs[this.seqid] = callback; 1258 | this.send_getCounter(key) 1259 | } 1260 | 1261 | FacebookServiceClient.prototype.send_getCounter = function(key) { 1262 | var output = new this.pClass(this.output); 1263 | output.writeMessageBegin('getCounter', Thrift.MessageType.CALL, this.seqid) 1264 | var args = new FacebookService_getCounter_args() 1265 | args.key = key 1266 | args.write(output) 1267 | output.writeMessageEnd() 1268 | return this.output.flush() 1269 | } 1270 | 1271 | FacebookServiceClient.prototype.recv_getCounter = function(input, mtype, rseqid) { 1272 | var callback = this._reqs[rseqid] || function() { 1273 | }; 1274 | delete this._reqs[rseqid]; 1275 | if (mtype == Thrift.MessageType.EXCEPTION) { 1276 | var x = new Thrift.TApplicationException() 1277 | x.read(input) 1278 | input.readMessageEnd() 1279 | return callback(x); 1280 | } 1281 | var result = new FacebookService_getCounter_result() 1282 | result.read(input) 1283 | input.readMessageEnd() 1284 | 1285 | if (null != result.success) { 1286 | return callback(null, result.success); 1287 | } 1288 | return callback("getCounter failed: unknown result"); 1289 | } 1290 | FacebookServiceClient.prototype.setOption = function(key, value, callback) { 1291 | this.seqid += 1; 1292 | this._reqs[this.seqid] = callback; 1293 | this.send_setOption(key, value) 1294 | } 1295 | 1296 | FacebookServiceClient.prototype.send_setOption = function(key, value) { 1297 | var output = new this.pClass(this.output); 1298 | output.writeMessageBegin('setOption', Thrift.MessageType.CALL, this.seqid) 1299 | var args = new FacebookService_setOption_args() 1300 | args.key = key 1301 | args.value = value 1302 | args.write(output) 1303 | output.writeMessageEnd() 1304 | return this.output.flush() 1305 | } 1306 | 1307 | FacebookServiceClient.prototype.recv_setOption = function(input, mtype, rseqid) { 1308 | var callback = this._reqs[rseqid] || function() { 1309 | }; 1310 | delete this._reqs[rseqid]; 1311 | if (mtype == Thrift.MessageType.EXCEPTION) { 1312 | var x = new Thrift.TApplicationException() 1313 | x.read(input) 1314 | input.readMessageEnd() 1315 | return callback(x); 1316 | } 1317 | var result = new FacebookService_setOption_result() 1318 | result.read(input) 1319 | input.readMessageEnd() 1320 | 1321 | callback(null) 1322 | } 1323 | FacebookServiceClient.prototype.getOption = function(key, callback) { 1324 | this.seqid += 1; 1325 | this._reqs[this.seqid] = callback; 1326 | this.send_getOption(key) 1327 | } 1328 | 1329 | FacebookServiceClient.prototype.send_getOption = function(key) { 1330 | var output = new this.pClass(this.output); 1331 | output.writeMessageBegin('getOption', Thrift.MessageType.CALL, this.seqid) 1332 | var args = new FacebookService_getOption_args() 1333 | args.key = key 1334 | args.write(output) 1335 | output.writeMessageEnd() 1336 | return this.output.flush() 1337 | } 1338 | 1339 | FacebookServiceClient.prototype.recv_getOption = function(input, mtype, rseqid) { 1340 | var callback = this._reqs[rseqid] || function() { 1341 | }; 1342 | delete this._reqs[rseqid]; 1343 | if (mtype == Thrift.MessageType.EXCEPTION) { 1344 | var x = new Thrift.TApplicationException() 1345 | x.read(input) 1346 | input.readMessageEnd() 1347 | return callback(x); 1348 | } 1349 | var result = new FacebookService_getOption_result() 1350 | result.read(input) 1351 | input.readMessageEnd() 1352 | 1353 | if (null != result.success) { 1354 | return callback(null, result.success); 1355 | } 1356 | return callback("getOption failed: unknown result"); 1357 | } 1358 | FacebookServiceClient.prototype.getOptions = function(callback) { 1359 | this.seqid += 1; 1360 | this._reqs[this.seqid] = callback; 1361 | this.send_getOptions() 1362 | } 1363 | 1364 | FacebookServiceClient.prototype.send_getOptions = function() { 1365 | var output = new this.pClass(this.output); 1366 | output.writeMessageBegin('getOptions', Thrift.MessageType.CALL, this.seqid) 1367 | var args = new FacebookService_getOptions_args() 1368 | args.write(output) 1369 | output.writeMessageEnd() 1370 | return this.output.flush() 1371 | } 1372 | 1373 | FacebookServiceClient.prototype.recv_getOptions = function(input, mtype, rseqid) { 1374 | var callback = this._reqs[rseqid] || function() { 1375 | }; 1376 | delete this._reqs[rseqid]; 1377 | if (mtype == Thrift.MessageType.EXCEPTION) { 1378 | var x = new Thrift.TApplicationException() 1379 | x.read(input) 1380 | input.readMessageEnd() 1381 | return callback(x); 1382 | } 1383 | var result = new FacebookService_getOptions_result() 1384 | result.read(input) 1385 | input.readMessageEnd() 1386 | 1387 | if (null != result.success) { 1388 | return callback(null, result.success); 1389 | } 1390 | return callback("getOptions failed: unknown result"); 1391 | } 1392 | FacebookServiceClient.prototype.getCpuProfile = function(profileDurationInSec, callback) { 1393 | this.seqid += 1; 1394 | this._reqs[this.seqid] = callback; 1395 | this.send_getCpuProfile(profileDurationInSec) 1396 | } 1397 | 1398 | FacebookServiceClient.prototype.send_getCpuProfile = function(profileDurationInSec) { 1399 | var output = new this.pClass(this.output); 1400 | output.writeMessageBegin('getCpuProfile', Thrift.MessageType.CALL, this.seqid) 1401 | var args = new FacebookService_getCpuProfile_args() 1402 | args.profileDurationInSec = profileDurationInSec 1403 | args.write(output) 1404 | output.writeMessageEnd() 1405 | return this.output.flush() 1406 | } 1407 | 1408 | FacebookServiceClient.prototype.recv_getCpuProfile = function(input, mtype, rseqid) { 1409 | var callback = this._reqs[rseqid] || function() { 1410 | }; 1411 | delete this._reqs[rseqid]; 1412 | if (mtype == Thrift.MessageType.EXCEPTION) { 1413 | var x = new Thrift.TApplicationException() 1414 | x.read(input) 1415 | input.readMessageEnd() 1416 | return callback(x); 1417 | } 1418 | var result = new FacebookService_getCpuProfile_result() 1419 | result.read(input) 1420 | input.readMessageEnd() 1421 | 1422 | if (null != result.success) { 1423 | return callback(null, result.success); 1424 | } 1425 | return callback("getCpuProfile failed: unknown result"); 1426 | } 1427 | FacebookServiceClient.prototype.aliveSince = function(callback) { 1428 | this.seqid += 1; 1429 | this._reqs[this.seqid] = callback; 1430 | this.send_aliveSince() 1431 | } 1432 | 1433 | FacebookServiceClient.prototype.send_aliveSince = function() { 1434 | var output = new this.pClass(this.output); 1435 | output.writeMessageBegin('aliveSince', Thrift.MessageType.CALL, this.seqid) 1436 | var args = new FacebookService_aliveSince_args() 1437 | args.write(output) 1438 | output.writeMessageEnd() 1439 | return this.output.flush() 1440 | } 1441 | 1442 | FacebookServiceClient.prototype.recv_aliveSince = function(input, mtype, rseqid) { 1443 | var callback = this._reqs[rseqid] || function() { 1444 | }; 1445 | delete this._reqs[rseqid]; 1446 | if (mtype == Thrift.MessageType.EXCEPTION) { 1447 | var x = new Thrift.TApplicationException() 1448 | x.read(input) 1449 | input.readMessageEnd() 1450 | return callback(x); 1451 | } 1452 | var result = new FacebookService_aliveSince_result() 1453 | result.read(input) 1454 | input.readMessageEnd() 1455 | 1456 | if (null != result.success) { 1457 | return callback(null, result.success); 1458 | } 1459 | return callback("aliveSince failed: unknown result"); 1460 | } 1461 | FacebookServiceClient.prototype.reinitialize = function(callback) { 1462 | this.seqid += 1; 1463 | this._reqs[this.seqid] = callback; 1464 | this.send_reinitialize() 1465 | } 1466 | 1467 | FacebookServiceClient.prototype.send_reinitialize = function() { 1468 | var output = new this.pClass(this.output); 1469 | output.writeMessageBegin('reinitialize', Thrift.MessageType.CALL, this.seqid) 1470 | var args = new FacebookService_reinitialize_args() 1471 | args.write(output) 1472 | output.writeMessageEnd() 1473 | return this.output.flush() 1474 | } 1475 | FacebookServiceClient.prototype.shutdown = function(callback) { 1476 | this.seqid += 1; 1477 | this._reqs[this.seqid] = callback; 1478 | this.send_shutdown() 1479 | } 1480 | 1481 | FacebookServiceClient.prototype.send_shutdown = function() { 1482 | var output = new this.pClass(this.output); 1483 | output.writeMessageBegin('shutdown', Thrift.MessageType.CALL, this.seqid) 1484 | var args = new FacebookService_shutdown_args() 1485 | args.write(output) 1486 | output.writeMessageEnd() 1487 | return this.output.flush() 1488 | } 1489 | var FacebookServiceProcessor = exports.Processor = function(handler) { 1490 | this._handler = handler 1491 | } 1492 | FacebookServiceProcessor.prototype.process = function(input, output) { 1493 | var r = input.readMessageBegin() 1494 | if (this['process_' + r.fname]) { 1495 | return this['process_' + r.fname].call(this, r.rseqid, input, output) 1496 | } else { 1497 | input.skip(Thrift.Type.STRUCT) 1498 | input.readMessageEnd() 1499 | var x = new Thrift.TApplicationException(Thrift.TApplicationExceptionType.UNKNOWN_METHOD, 'Unknown function ' + r.fname) 1500 | output.writeMessageBegin(r.fname, Thrift.MessageType.Exception, r.rseqid) 1501 | x.write(output) 1502 | output.writeMessageEnd() 1503 | output.flush() 1504 | } 1505 | } 1506 | 1507 | FacebookServiceProcessor.prototype.process_getName = function(seqid, input, output) { 1508 | var args = new FacebookService_getName_args() 1509 | args.read(input) 1510 | input.readMessageEnd() 1511 | var result = new FacebookService_getName_result() 1512 | this._handler.getName(function(success) { 1513 | result.success = success 1514 | output.writeMessageBegin("getName", Thrift.MessageType.REPLY, seqid) 1515 | result.write(output) 1516 | output.writeMessageEnd() 1517 | output.flush() 1518 | }) 1519 | } 1520 | 1521 | FacebookServiceProcessor.prototype.process_getVersion = function(seqid, input, output) { 1522 | var args = new FacebookService_getVersion_args() 1523 | args.read(input) 1524 | input.readMessageEnd() 1525 | var result = new FacebookService_getVersion_result() 1526 | this._handler.getVersion(function(success) { 1527 | result.success = success 1528 | output.writeMessageBegin("getVersion", Thrift.MessageType.REPLY, seqid) 1529 | result.write(output) 1530 | output.writeMessageEnd() 1531 | output.flush() 1532 | }) 1533 | } 1534 | 1535 | FacebookServiceProcessor.prototype.process_getStatus = function(seqid, input, output) { 1536 | var args = new FacebookService_getStatus_args() 1537 | args.read(input) 1538 | input.readMessageEnd() 1539 | var result = new FacebookService_getStatus_result() 1540 | this._handler.getStatus(function(success) { 1541 | result.success = success 1542 | output.writeMessageBegin("getStatus", Thrift.MessageType.REPLY, seqid) 1543 | result.write(output) 1544 | output.writeMessageEnd() 1545 | output.flush() 1546 | }) 1547 | } 1548 | 1549 | FacebookServiceProcessor.prototype.process_getStatusDetails = function(seqid, input, output) { 1550 | var args = new FacebookService_getStatusDetails_args() 1551 | args.read(input) 1552 | input.readMessageEnd() 1553 | var result = new FacebookService_getStatusDetails_result() 1554 | this._handler.getStatusDetails(function(success) { 1555 | result.success = success 1556 | output.writeMessageBegin("getStatusDetails", Thrift.MessageType.REPLY, seqid) 1557 | result.write(output) 1558 | output.writeMessageEnd() 1559 | output.flush() 1560 | }) 1561 | } 1562 | 1563 | FacebookServiceProcessor.prototype.process_getCounters = function(seqid, input, output) { 1564 | var args = new FacebookService_getCounters_args() 1565 | args.read(input) 1566 | input.readMessageEnd() 1567 | var result = new FacebookService_getCounters_result() 1568 | this._handler.getCounters(function(success) { 1569 | result.success = success 1570 | output.writeMessageBegin("getCounters", Thrift.MessageType.REPLY, seqid) 1571 | result.write(output) 1572 | output.writeMessageEnd() 1573 | output.flush() 1574 | }) 1575 | } 1576 | 1577 | FacebookServiceProcessor.prototype.process_getCounter = function(seqid, input, output) { 1578 | var args = new FacebookService_getCounter_args() 1579 | args.read(input) 1580 | input.readMessageEnd() 1581 | var result = new FacebookService_getCounter_result() 1582 | this._handler.getCounter(args.key, function(success) { 1583 | result.success = success 1584 | output.writeMessageBegin("getCounter", Thrift.MessageType.REPLY, seqid) 1585 | result.write(output) 1586 | output.writeMessageEnd() 1587 | output.flush() 1588 | }) 1589 | } 1590 | 1591 | FacebookServiceProcessor.prototype.process_setOption = function(seqid, input, output) { 1592 | var args = new FacebookService_setOption_args() 1593 | args.read(input) 1594 | input.readMessageEnd() 1595 | var result = new FacebookService_setOption_result() 1596 | this._handler.setOption(args.key, args.value, function(success) { 1597 | result.success = success 1598 | output.writeMessageBegin("setOption", Thrift.MessageType.REPLY, seqid) 1599 | result.write(output) 1600 | output.writeMessageEnd() 1601 | output.flush() 1602 | }) 1603 | } 1604 | 1605 | FacebookServiceProcessor.prototype.process_getOption = function(seqid, input, output) { 1606 | var args = new FacebookService_getOption_args() 1607 | args.read(input) 1608 | input.readMessageEnd() 1609 | var result = new FacebookService_getOption_result() 1610 | this._handler.getOption(args.key, function(success) { 1611 | result.success = success 1612 | output.writeMessageBegin("getOption", Thrift.MessageType.REPLY, seqid) 1613 | result.write(output) 1614 | output.writeMessageEnd() 1615 | output.flush() 1616 | }) 1617 | } 1618 | 1619 | FacebookServiceProcessor.prototype.process_getOptions = function(seqid, input, output) { 1620 | var args = new FacebookService_getOptions_args() 1621 | args.read(input) 1622 | input.readMessageEnd() 1623 | var result = new FacebookService_getOptions_result() 1624 | this._handler.getOptions(function(success) { 1625 | result.success = success 1626 | output.writeMessageBegin("getOptions", Thrift.MessageType.REPLY, seqid) 1627 | result.write(output) 1628 | output.writeMessageEnd() 1629 | output.flush() 1630 | }) 1631 | } 1632 | 1633 | FacebookServiceProcessor.prototype.process_getCpuProfile = function(seqid, input, output) { 1634 | var args = new FacebookService_getCpuProfile_args() 1635 | args.read(input) 1636 | input.readMessageEnd() 1637 | var result = new FacebookService_getCpuProfile_result() 1638 | this._handler.getCpuProfile(args.profileDurationInSec, function(success) { 1639 | result.success = success 1640 | output.writeMessageBegin("getCpuProfile", Thrift.MessageType.REPLY, seqid) 1641 | result.write(output) 1642 | output.writeMessageEnd() 1643 | output.flush() 1644 | }) 1645 | } 1646 | 1647 | FacebookServiceProcessor.prototype.process_aliveSince = function(seqid, input, output) { 1648 | var args = new FacebookService_aliveSince_args() 1649 | args.read(input) 1650 | input.readMessageEnd() 1651 | var result = new FacebookService_aliveSince_result() 1652 | this._handler.aliveSince(function(success) { 1653 | result.success = success 1654 | output.writeMessageBegin("aliveSince", Thrift.MessageType.REPLY, seqid) 1655 | result.write(output) 1656 | output.writeMessageEnd() 1657 | output.flush() 1658 | }) 1659 | } 1660 | 1661 | FacebookServiceProcessor.prototype.process_reinitialize = function(seqid, input, output) { 1662 | var args = new FacebookService_reinitialize_args() 1663 | args.read(input) 1664 | input.readMessageEnd() 1665 | this._handler.reinitialize() 1666 | } 1667 | 1668 | FacebookServiceProcessor.prototype.process_shutdown = function(seqid, input, output) { 1669 | var args = new FacebookService_shutdown_args() 1670 | args.read(input) 1671 | input.readMessageEnd() 1672 | this._handler.shutdown() 1673 | } 1674 | 1675 | -------------------------------------------------------------------------------- /lib/gen-nodejs/fb303_types.js: -------------------------------------------------------------------------------- 1 | // 2 | // Autogenerated by Thrift 3 | // 4 | // DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | // 6 | var Thrift = require('thrift').Thrift; 7 | var ttypes = module.exports = {}; 8 | ttypes.fb_status = { 9 | 'DEAD' : 0 10 | ,'STARTING' : 1 11 | ,'ALIVE' : 2 12 | ,'STOPPING' : 3 13 | ,'STOPPED' : 4 14 | ,'WARNING' : 5 15 | } 16 | -------------------------------------------------------------------------------- /lib/gen-nodejs/scribe.js: -------------------------------------------------------------------------------- 1 | // 2 | // Autogenerated by Thrift 3 | // 4 | // DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | // 6 | var Thrift = require('thrift').Thrift; 7 | var fb303_ttypes = require('./fb303_types') 8 | 9 | 10 | var FacebookService = require('./FacebookService') 11 | var FacebookServiceClient = FacebookService.Client 12 | var ttypes = require('./scribe_types'); 13 | //HELPER FUNCTIONS AND STRUCTURES 14 | 15 | var scribe_Log_args = function(args) { 16 | this.messages = null 17 | if (args != null) { 18 | if (null != args.messages) 19 | this.messages = args.messages 20 | } 21 | } 22 | scribe_Log_args.prototype = {} 23 | scribe_Log_args.prototype.read = function(input) { 24 | var ret = input.readStructBegin() 25 | while (1) { 26 | var ret = input.readFieldBegin() 27 | var fname = ret.fname 28 | var ftype = ret.ftype 29 | var fid = ret.fid 30 | if (ftype == Thrift.Type.STOP) 31 | break 32 | switch (fid) { 33 | case 1: 34 | if (ftype == Thrift.Type.LIST) { 35 | { 36 | var _size0 = 0 37 | var rtmp3 38 | this.messages = [] 39 | var _etype3 = 0 40 | rtmp3 = input.readListBegin() 41 | _etype3 = rtmp3.etype 42 | _size0 = rtmp3.size 43 | for (var _i4 = 0; _i4 < _size0; ++_i4) { 44 | var elem5 = null 45 | elem5 = new ttypes.LogEntry() 46 | elem5.read(input) 47 | this.messages.push(elem5) 48 | } 49 | input.readListEnd() 50 | } 51 | } else { 52 | input.skip(ftype) 53 | } 54 | break 55 | default: 56 | input.skip(ftype) 57 | } 58 | input.readFieldEnd() 59 | } 60 | input.readStructEnd() 61 | return 62 | } 63 | 64 | scribe_Log_args.prototype.write = function(output) { 65 | output.writeStructBegin('scribe_Log_args') 66 | if (null != this.messages) { 67 | output.writeFieldBegin('messages', Thrift.Type.LIST, 1) 68 | { 69 | output.writeListBegin(Thrift.Type.STRUCT, this.messages.length) 70 | { 71 | for (var iter6 in this.messages) { 72 | if (this.messages.hasOwnProperty(iter6)) { 73 | iter6 = this.messages[iter6] 74 | iter6.write(output) 75 | } 76 | } 77 | } 78 | output.writeListEnd() 79 | } 80 | output.writeFieldEnd() 81 | } 82 | output.writeFieldStop() 83 | output.writeStructEnd() 84 | return 85 | } 86 | 87 | var scribe_Log_result = function(args) { 88 | this.success = null 89 | if (args != null) { 90 | if (null != args.success) 91 | this.success = args.success 92 | } 93 | } 94 | scribe_Log_result.prototype = {} 95 | scribe_Log_result.prototype.read = function(input) { 96 | var ret = input.readStructBegin() 97 | while (1) { 98 | var ret = input.readFieldBegin() 99 | var fname = ret.fname 100 | var ftype = ret.ftype 101 | var fid = ret.fid 102 | if (ftype == Thrift.Type.STOP) 103 | break 104 | switch (fid) { 105 | case 0: 106 | if (ftype == Thrift.Type.I32) { 107 | this.success = input.readI32() 108 | } else { 109 | input.skip(ftype) 110 | } 111 | break 112 | default: 113 | input.skip(ftype) 114 | } 115 | input.readFieldEnd() 116 | } 117 | input.readStructEnd() 118 | return 119 | } 120 | 121 | scribe_Log_result.prototype.write = function(output) { 122 | output.writeStructBegin('scribe_Log_result') 123 | if (null != this.success) { 124 | output.writeFieldBegin('success', Thrift.Type.I32, 0) 125 | output.writeI32(this.success) 126 | output.writeFieldEnd() 127 | } 128 | output.writeFieldStop() 129 | output.writeStructEnd() 130 | return 131 | } 132 | 133 | var scribeClient = exports.Client = function(output, pClass) { 134 | this.output = output; 135 | this.pClass = pClass; 136 | this.seqid = 0; 137 | this._reqs = {} 138 | } 139 | Thrift.inherits(scribeClient, FacebookServiceClient) 140 | scribeClient.prototype.Log = function(messages, callback) { 141 | this.seqid += 1; 142 | this._reqs[this.seqid] = callback; 143 | this.send_Log(messages) 144 | } 145 | 146 | scribeClient.prototype.send_Log = function(messages) { 147 | var output = new this.pClass(this.output); 148 | output.writeMessageBegin('Log', Thrift.MessageType.CALL, this.seqid) 149 | var args = new scribe_Log_args() 150 | args.messages = messages 151 | args.write(output) 152 | output.writeMessageEnd() 153 | return this.output.flush() 154 | } 155 | 156 | scribeClient.prototype.recv_Log = function(input, mtype, rseqid) { 157 | var callback = this._reqs[rseqid] || function() { 158 | }; 159 | delete this._reqs[rseqid]; 160 | if (mtype == Thrift.MessageType.EXCEPTION) { 161 | var x = new Thrift.TApplicationException() 162 | x.read(input) 163 | input.readMessageEnd() 164 | return callback(x); 165 | } 166 | var result = new scribe_Log_result() 167 | result.read(input) 168 | input.readMessageEnd() 169 | 170 | if (null != result.success) { 171 | return callback(null, result.success); 172 | } 173 | return callback("Log failed: unknown result"); 174 | } 175 | var scribeProcessor = exports.Processor = function(handler) { 176 | this._handler = handler 177 | } 178 | scribeProcessor.prototype.process = function(input, output) { 179 | var r = input.readMessageBegin() 180 | if (this['process_' + r.fname]) { 181 | return this['process_' + r.fname].call(this, r.rseqid, input, output) 182 | } else { 183 | input.skip(Thrift.Type.STRUCT) 184 | input.readMessageEnd() 185 | var x = new Thrift.TApplicationException(Thrift.TApplicationExceptionType.UNKNOWN_METHOD, 'Unknown function ' + r.fname) 186 | output.writeMessageBegin(r.fname, Thrift.MessageType.Exception, r.rseqid) 187 | x.write(output) 188 | output.writeMessageEnd() 189 | output.flush() 190 | } 191 | } 192 | 193 | scribeProcessor.prototype.process_Log = function(seqid, input, output) { 194 | var args = new scribe_Log_args() 195 | args.read(input) 196 | input.readMessageEnd() 197 | var result = new scribe_Log_result() 198 | this._handler.Log(args.messages, function(success) { 199 | result.success = success 200 | output.writeMessageBegin("Log", Thrift.MessageType.REPLY, seqid) 201 | result.write(output) 202 | output.writeMessageEnd() 203 | output.flush() 204 | }) 205 | } 206 | 207 | -------------------------------------------------------------------------------- /lib/gen-nodejs/scribe_types.js: -------------------------------------------------------------------------------- 1 | // 2 | // Autogenerated by Thrift 3 | // 4 | // DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | // 6 | var Thrift = require('thrift').Thrift; 7 | var ttypes = module.exports = {}; 8 | ttypes.ResultCode = { 9 | 'OK' : 0 10 | ,'TRY_LATER' : 1 11 | } 12 | var LogEntry = module.exports.LogEntry = function(args) { 13 | this.category = null 14 | this.message = null 15 | if (args != null) { 16 | if (null != args.category) 17 | this.category = args.category 18 | if (null != args.message) 19 | this.message = args.message 20 | } 21 | } 22 | LogEntry.prototype = {} 23 | LogEntry.prototype.read = function(input) { 24 | var ret = input.readStructBegin() 25 | while (1) { 26 | var ret = input.readFieldBegin() 27 | var fname = ret.fname 28 | var ftype = ret.ftype 29 | var fid = ret.fid 30 | if (ftype == Thrift.Type.STOP) 31 | break 32 | switch (fid) { 33 | case 1: 34 | if (ftype == Thrift.Type.STRING) { 35 | this.category = input.readString() 36 | } else { 37 | input.skip(ftype) 38 | } 39 | break 40 | case 2: 41 | if (ftype == Thrift.Type.STRING) { 42 | this.message = input.readString() 43 | } else { 44 | input.skip(ftype) 45 | } 46 | break 47 | default: 48 | input.skip(ftype) 49 | } 50 | input.readFieldEnd() 51 | } 52 | input.readStructEnd() 53 | return 54 | } 55 | 56 | LogEntry.prototype.write = function(output) { 57 | output.writeStructBegin('LogEntry') 58 | if (null != this.category) { 59 | output.writeFieldBegin('category', Thrift.Type.STRING, 1) 60 | output.writeString(this.category) 61 | output.writeFieldEnd() 62 | } 63 | if (null != this.message) { 64 | output.writeFieldBegin('message', Thrift.Type.STRING, 2) 65 | output.writeString(this.message) 66 | output.writeFieldEnd() 67 | } 68 | output.writeFieldStop() 69 | output.writeStructEnd() 70 | return 71 | } 72 | 73 | -------------------------------------------------------------------------------- /lib/logger.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * Node-scribe (scribe in npmjs) 3 | * Scribe client for node.js 4 | * Copyright(c) 2011 Applifier Ltd 5 | * MIT Licensed 6 | */ 7 | 8 | 9 | /** 10 | * Module dependencies. 11 | */ 12 | 13 | var os = require('os'); 14 | var systemConsole = global.console; 15 | 16 | // console object 17 | var formatRegExp = /%[sdj]/g; 18 | var format = exports.format = function(f) { 19 | var util = require('util'); 20 | 21 | if (typeof f !== 'string') { 22 | var objects = []; 23 | for (var i = 0; i < arguments.length; i++) { 24 | objects.push(util.inspect(arguments[i])); 25 | } 26 | return objects.join(' '); 27 | } 28 | 29 | 30 | i = 1; 31 | var args = arguments; 32 | var str = String(f).replace(formatRegExp, function(x) { 33 | switch (x) { 34 | case '%s': 35 | return String(args[i++]); 36 | case '%d': 37 | return Number(args[i++]); 38 | case '%j': 39 | return JSON.stringify(args[i++]); 40 | default: 41 | return x; 42 | } 43 | }); 44 | for (var len = args.length, x = args[i]; i < len; x = args[++i]) { 45 | if (x === null || typeof x !== 'object') { 46 | str += ' ' + x; 47 | } else { 48 | str += ' ' + util.inspect(x); 49 | } 50 | } 51 | return str; 52 | } 53 | 54 | var levelNames = exports.levelNames = { 55 | 0 : "EMERG", 56 | 1 : "ALERT", 57 | 2 : "CRITICAL", 58 | 3 : "ERROR", 59 | 4 : "WARN", 60 | 5 : "NOTICE", 61 | 6 : "INFO", 62 | 7 : "DEBUG" 63 | }; 64 | 65 | var Logger = exports.Logger = function (scribe, category) { 66 | 67 | if (scribe == undefined || category == undefined) { 68 | throw new Error("Scribe and category should be defined"); 69 | } 70 | 71 | this.stackRegex = new RegExp("Error.+?\t.+?\t.+?\t +?at (.+?)\t"); 72 | this.lastLoggedLeve = null; 73 | this.lastLoggedLine = null; 74 | 75 | this.scribe = scribe; 76 | this.scribeCategory = category; 77 | 78 | this.hostname = os.hostname(); 79 | 80 | this.levelNames = exports.levelNames; 81 | 82 | }; 83 | 84 | Logger.LOG_DEBUG = 7; 85 | Logger.LOG_INFO = 6; 86 | Logger.LOG_WARNING = 4; 87 | Logger.LOG_ERROR = 3; 88 | Logger.LOG_CRITICAL = 2; 89 | 90 | Logger.prototype.releaseConsole = function() { 91 | // This worked in node 0.4.x 92 | if (process.version[3] == '4') { 93 | global.console = this; 94 | 95 | // This works on 0.6 and upwards 96 | } else { 97 | //global.__defineGetter__('console', systemConsole); 98 | 99 | // updated to work with node 0.8 100 | global.__defineGetter__('console', function () { 101 | return systemConsole; 102 | }); 103 | } 104 | }; 105 | 106 | Logger.prototype.replaceConsole = function() { 107 | 108 | var self = this; 109 | 110 | // This worked in node 0.4.x 111 | if (process.version[3] == '4') { 112 | global.console = this; 113 | 114 | // This works on 0.6 and upwards 115 | } else { 116 | global.__defineGetter__('console', function() { 117 | return self; 118 | }); 119 | } 120 | 121 | }; 122 | 123 | Logger.prototype.extractCalledFromStack = function () { 124 | var stack = new Error().stack; 125 | stack = stack.replace(/\n/g, "\t"); 126 | var r = this.stackRegex.exec(stack); 127 | if(r == null) { 128 | return ""; 129 | } 130 | return r[1]; 131 | }; 132 | 133 | exports.formatTimestamp = Logger.prototype.formatTimestamp = function(t) { 134 | 135 | var month = "" + (t.getUTCMonth() + 1); 136 | if (month.length == 1) { 137 | month = "0" + month; 138 | } 139 | 140 | var days = "" + t.getUTCDate(); 141 | if (days.length == 1) { 142 | days = "0" + days; 143 | } 144 | 145 | var hours = "" + t.getUTCHours(); 146 | if (hours.length == 1) { 147 | hours = "0" + hours; 148 | } 149 | 150 | var minutes = "" + t.getUTCMinutes(); 151 | if (minutes.length == 1) { 152 | minutes = "0" + minutes; 153 | } 154 | 155 | var seconds = "" + t.getUTCSeconds(); 156 | if (seconds.length == 1) { 157 | seconds = "0" + seconds; 158 | } 159 | 160 | return t.getFullYear() + "-" + month + "-" + days + " " + hours + ":" + minutes + ":" + seconds; 161 | }; 162 | 163 | Logger.prototype.logMessage = function (level, msg) { 164 | var str = this.levelNames[level] + "\t" + this.hostname + "\t" + process.pid + "\t" + this.extractCalledFromStack() + "\t" + msg; 165 | 166 | this.lastLoggedLevel = level; 167 | this.lastLoggedLine = str; 168 | 169 | if (this.scribe) { 170 | this.scribe.send(this.scribeCategory, this.formatTimestamp(new Date()) + "\t" + str); 171 | } else { 172 | process.stdout.write(this.levelNames[level] + "\t" + process.pid + "\t" + this.extractCalledFromStack() + "\t" + msg + "\n"); 173 | } 174 | 175 | }; 176 | 177 | Logger.prototype.debug = Logger.prototype.log = function (msg) { 178 | this.logMessage(Logger.LOG_DEBUG, format.apply(this, arguments)); 179 | }; 180 | 181 | Logger.prototype.info = function (msg) { 182 | this.logMessage(Logger.LOG_INFO, format.apply(this, arguments)); 183 | }; 184 | Logger.prototype.warn = function (msg) { 185 | this.logMessage(Logger.LOG_WARNING, format.apply(this, arguments)); 186 | }; 187 | Logger.prototype.error = function (msg) { 188 | this.logMessage(Logger.LOG_ERROR, format.apply(this, arguments)); 189 | }; 190 | Logger.prototype.critical = function (msg) { 191 | this.logMessage(Logger.LOG_CRITICAL, format.apply(this, arguments)); 192 | }; 193 | 194 | Logger.prototype.dir = function(obj, level) { 195 | var util = require('util'); 196 | if (!level) { 197 | level = 'DEBUG'; 198 | } 199 | 200 | var levelNumber = this.levelNames[level]; 201 | 202 | this.logMessage(levelNumber, util.inspect(obj)); 203 | }; 204 | 205 | Logger.prototype.trace = function(label) { 206 | // TODO probably can to do this better with V8's debug object once that is 207 | // exposed. 208 | var err = new Error; 209 | err.name = 'Trace'; 210 | err.message = label || ''; 211 | Error.captureStackTrace(err, arguments.callee); 212 | this.error(err.stack); 213 | }; 214 | 215 | 216 | Logger.prototype.assert = function(expression) { 217 | if (!expression) { 218 | var arr = Array.prototype.slice.call(arguments, 1); 219 | require('assert').ok(false, format.apply(this, arr)); 220 | } 221 | }; 222 | -------------------------------------------------------------------------------- /lib/requestlog.js: -------------------------------------------------------------------------------- 1 | var Logger = require('./logger'); 2 | 3 | var crypto = require('crypto'); 4 | 5 | exports.formatTimestamp = Logger.formatTimestamp; 6 | exports.levelNames = Logger.levelNames; 7 | 8 | function randomString() { 9 | return crypto.pseudoRandomBytes(12).toString('base64'); 10 | } 11 | 12 | var stackRegex = new RegExp("Error.+?\t.+?\t.+?\t +?at (.+?)\t.+"); 13 | 14 | var extractCalledFromStack = function () { 15 | var stack = new Error().stack; 16 | stack = stack.replace(/\n/g, "\t"); 17 | 18 | var r = stackRegex.exec(stack); 19 | 20 | if (r == null) { 21 | return ""; 22 | } 23 | return r[1]; 24 | }; 25 | 26 | 27 | var logMessage = function (level, req, msg) { 28 | 29 | var line = extractCalledFromStack(); 30 | 31 | req.log.writer(level, req.log.id, line, msg); 32 | }; 33 | 34 | /** 35 | * 36 | * Creates a middleware which will inject every req object with a log object. 37 | * The log object contains an pseudo-unique id for each request in the req.log.id variable. 38 | * 39 | * In addition the req.log object contains console.log compatible logging functions: 40 | * log, info, warn, error, critical. 41 | * 42 | * Each log message logged using those methods is passed into the custom writer() function, 43 | * which the user must pass in the factory constructor. 44 | * 45 | * The writer takes the following arguments: 46 | * function writer(level, request_id, line, message), where: 47 | * - level is the numeric log level as defined in Logger: 48 | * Logger.LOG_DEBUG = 7; 49 | * Logger.LOG_INFO = 6; 50 | * Logger.LOG_WARNING = 4; 51 | * Logger.LOG_ERROR = 3; 52 | * Logger.LOG_CRITICAL = 2; 53 | * - request_id is the pseudo-randomly generated unique id for the request 54 | * - line is a stacktrace line where the log message was generated, in form of "/path/to/file.js:line:character", eg "/path:tio:file.js:282:24" 55 | * - message is a concatenated string of all the arguments passed to the log function 56 | * 57 | * Here's an example how we have used the writer to feed log lines to scribe: 58 | * 59 | * var hostname = require('os').hostname(); 60 | * app.use(RequestLog.factory(function (level, id, line, msg) { 61 | * var str = RequestLog.formatTimestamp(new Date()) + "\t" + RequestLog.levelNames[level] + "\t" + hostname + "\t" + process.pid + "\t" + line + "\t" + id + "\t" + msg; 62 | * scribe.send("comet", str); 63 | * })); 64 | * 65 | */ 66 | exports.factory = function (writer) { 67 | return function (req, res, next) { 68 | 69 | var id = randomString(); 70 | 71 | req.log = { 72 | log:function () { 73 | logMessage(Logger.Logger.LOG_DEBUG, req, Logger.format.apply(this, arguments)); 74 | }, 75 | info:function () { 76 | logMessage(Logger.Logger.LOG_INFO, req, Logger.format.apply(this, arguments)); 77 | }, 78 | warn:function () { 79 | logMessage(Logger.Logger.LOG_WARNING, req, Logger.format.apply(this, arguments)); 80 | }, 81 | error:function () { 82 | logMessage(Logger.Logger.LOG_ERROR, req, Logger.format.apply(this, arguments)); 83 | }, 84 | critical:function () { 85 | logMessage(Logger.Logger.LOG_CRITICAL, req, Logger.format.apply(this, arguments)); 86 | }, 87 | id:id, 88 | writer:writer 89 | }; 90 | 91 | next(); 92 | }; 93 | 94 | }; 95 | 96 | 97 | -------------------------------------------------------------------------------- /lib/scribe.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * Node-scribe (scribe in npmjs) 3 | * Scribe client for node.js 4 | * Copyright(c) 2011 Applifier Ltd 5 | * MIT Licensed 6 | */ 7 | 8 | 9 | /** 10 | * Module dependencies. 11 | */ 12 | 13 | var util = require('util'); 14 | var events = require('events'); 15 | 16 | var thrift = require('thrift'); 17 | var scribe = require('./gen-nodejs/scribe'); 18 | var scribe_types = require('./gen-nodejs/scribe_types'); 19 | 20 | /** 21 | * Constructor for the scribe client. 22 | @param {String} host Hostname of scribe server 23 | @param {Number} port The port where scribe server is running 24 | @param {Object} options Options (etc. autoReconnect {Boolean}, autoReconnectTimeout {Number} or [{Number}], other types 25 | will result in error) 26 | @type Scribe scribe client 27 | */ 28 | var Scribe = exports.Scribe = function(host, port, opt) { 29 | var self = this; 30 | 31 | this.host = host; 32 | this.port = Number(port); 33 | 34 | this.autoReconnect = opt && opt.autoReconnect ? true : false; 35 | this.autoReconnectTimeout = []; 36 | this.reconnecting = false; 37 | 38 | this.retries = 0; 39 | this.opened = false; 40 | 41 | if (opt && opt.autoReconnectTimeout) { 42 | if (opt.autoReconnectTimeout.constructor === Number) { 43 | this.autoReconnectTimeout = [opt.autoReconnectTimeout]; 44 | } else if (opt.autoReconnectTimeout.constructor === Array) { 45 | for (var i = 0; i < opt.autoReconnectTimeout.length; i++) { 46 | var timeout = opt.autoReconnectTimeout[i]; 47 | if (timeout.constructor !== Number) { 48 | throw new Error("autoReconnectTimeout should be Number or Array of numbers"); 49 | } 50 | this.autoReconnectTimeout.push(timeout); 51 | } 52 | } else { 53 | throw new Error("autoReconnectTimeout should be Number or Array of numbers"); 54 | } 55 | } 56 | 57 | this.client = null; 58 | this.connection = null; 59 | 60 | this.queue = []; 61 | 62 | // Define getters 63 | this.__defineGetter__("connected", function() { 64 | if (self.connection != null) { 65 | return self.connection.connected; 66 | } else { 67 | return false; 68 | } 69 | }); 70 | 71 | this.__defineGetter__("writable", function() { 72 | if (self.connection != null) { 73 | return self.connection.connection.writable; 74 | } else { 75 | return false; 76 | } 77 | }); 78 | 79 | }; 80 | 81 | util.inherits(Scribe, events.EventEmitter); 82 | 83 | /** 84 | * Open connection to scribe server 85 | @param {Function} callback which is called when connection is opened or and error occures 86 | */ 87 | Scribe.prototype.open = function(callback) { 88 | var self = this; 89 | this.opened = true; 90 | this.connection = thrift.createConnection(this.host, this.port); 91 | this.client = thrift.createClient(scribe, this.connection); 92 | 93 | this.connection.once('error', function(err) { 94 | if (callback) { 95 | callback(err, self); 96 | callback = null; 97 | } 98 | }); 99 | 100 | this.connection.once('connect', function() { 101 | self.retries = 0; 102 | self.emit('connect'); 103 | 104 | // Flush queue if not empty 105 | if (self.queue.length > 0) { 106 | self.flush(); 107 | } 108 | 109 | if (callback) { 110 | callback(null, self); 111 | callback = null; 112 | } 113 | }); 114 | 115 | this.connection.on('error', function(err) { 116 | self.processError(err); 117 | }); 118 | }; 119 | 120 | /** 121 | * Close connection 122 | */ 123 | Scribe.prototype.close = function() { 124 | this.opened = false; 125 | this.connection.end(); 126 | }; 127 | 128 | Scribe.prototype.flush = function() { 129 | var self = this; 130 | // Dont try to flush ih connection is not writable 131 | if (!this.writable) { 132 | // If connection was opened previously try to get it back on 133 | if (this.opened && this.autoReconnect) { 134 | this.retryConnection(); 135 | } 136 | return; 137 | } 138 | 139 | // Dont flush if queue is empty 140 | if (this.queue.length == 0) { 141 | return; 142 | } 143 | 144 | var queue = this.queue; 145 | this.queue = []; 146 | this.client.Log(queue, function(err, resultCode) { 147 | // If resultCode is 1 (0 = OK, 1 = Try again) add items back to queue 148 | if (resultCode === 1 || err) { 149 | self.queue = self.queue.concat(queue); 150 | // Auto flush in 3 seconds 151 | setTimeout(function() { 152 | self.flush(); 153 | }, 3000); 154 | } 155 | }); 156 | }; 157 | 158 | Scribe.prototype.processError = function(err) { 159 | this.emit('error', err); 160 | // If autoreconnect has been enabled, try connecting 161 | if (this.autoReconnect && !this.writable) { 162 | this.retryConnection(); 163 | } 164 | }; 165 | 166 | Scribe.prototype.retryConnection = function() { 167 | if (this.reconnecting) { 168 | return; 169 | } 170 | var self = this; 171 | this.reconnecting = true; 172 | var timeout = 3000; 173 | if (this.autoReconnectTimeout.length > 0) { 174 | if (this.retries < this.autoReconnectTimeout.length) { 175 | timeout = this.autoReconnectTimeout[this.retries]; 176 | } else { 177 | timeout = this.autoReconnectTimeout[this.autoReconnectTimeout.length - 1]; 178 | } 179 | } 180 | 181 | setTimeout(function() { 182 | self.emit('reconnecting'); 183 | self.open(function() { 184 | self.reconnecting = false; 185 | }); 186 | }, timeout); 187 | 188 | this.retries++; 189 | }; 190 | 191 | /** 192 | * Send log entry to scribe server 193 | @param {String} category Log category 194 | @param {String} message Log message 195 | */ 196 | Scribe.prototype.send = function(category, message) { 197 | var entry = new scribe_types.LogEntry({ 198 | category : category, 199 | message : message 200 | }); 201 | 202 | this.queue.push(entry); 203 | this.flush(); 204 | }; 205 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "scribe", 3 | "description": "Scribe client", 4 | "version": "0.0.10", 5 | "repository": { 6 | "type": "git", 7 | "url": "git://github.com/Applifier/node-scribe" 8 | }, 9 | "dependencies": { 10 | "thrift" : "0.7.0" 11 | }, 12 | "author": "Applifier " 13 | } 14 | -------------------------------------------------------------------------------- /test/logger.test.js: -------------------------------------------------------------------------------- 1 | var assert = require('assert'); 2 | var Scribe = require('../lib/scribe').Scribe; 3 | var scribeServer = require('../test_utils/scribeserver'); 4 | var Logger = require('../lib/logger').Logger; 5 | 6 | module.exports = { 7 | 'test construct': function() { 8 | var scribe = new Scribe("localhost", 8988); 9 | var logger = new Logger(scribe, "foo"); 10 | }, 11 | 'test sending data' : function() { 12 | var server = scribeServer.createServer(); 13 | server.on('log', function(entry) { 14 | assert.equal(entry.length, 1, "Should have received one entry"); 15 | assert.equal(entry[0].category, "foo"); 16 | assert.ok(entry[0].message.indexOf("\tfoobar") > -1); 17 | assert.ok(entry[0].message.indexOf("\tDEBUG") > -1); 18 | setTimeout(function() { 19 | scribe.close(); 20 | server.close(); 21 | }, 500); 22 | }); 23 | server.listen(8992); 24 | var scribe = new Scribe("localhost", 8992); 25 | var logger = new Logger(scribe, "foo"); 26 | scribe.open(function(err, client) { 27 | logger.log("foobar"); 28 | }); 29 | }, 30 | 'test replacing console' : function() { 31 | var server = scribeServer.createServer(); 32 | server.on('log', function(entry) { 33 | assert.equal(entry.length, 1, "Should have received one entry"); 34 | assert.equal(entry[0].category, "foo"); 35 | assert.ok(entry[0].message.indexOf("\tfoobar") > -1); 36 | assert.ok(entry[0].message.indexOf("\tDEBUG") > -1); 37 | setTimeout(function() { 38 | scribe.close(); 39 | server.close(); 40 | }, 500); 41 | }); 42 | server.listen(8993); 43 | var scribe = new Scribe("localhost", 8993); 44 | var logger = new Logger(scribe, "foo"); 45 | logger.replaceConsole(); 46 | scribe.open(function(err, client) { 47 | console.log("foobar"); 48 | logger.releaseConsole(); 49 | }); 50 | } 51 | }; 52 | -------------------------------------------------------------------------------- /test/requestlog.test.js: -------------------------------------------------------------------------------- 1 | var RequestLog = require('../lib/requestlog'); 2 | var assert = require('assert'); 3 | 4 | test("constructor", function(done) { 5 | 6 | assert.ok(RequestLog); 7 | 8 | done(); 9 | }); 10 | 11 | 12 | test("creates request id", function(done) { 13 | 14 | var req = {}; 15 | var res = {}; 16 | 17 | var middleware = RequestLog.factory(); 18 | 19 | assert.ok(middleware != null); 20 | 21 | done(); 22 | }); 23 | 24 | 25 | test("can log something", function(done) { 26 | 27 | var req = {}; 28 | var res = {}; 29 | var buf = ""; 30 | 31 | RequestLog.factory(function (level, id, line, msg) { 32 | buf += msg; 33 | })(req, res, function() {}); 34 | 35 | 36 | 37 | req.log.log("test"); 38 | 39 | assert.equal(buf, "test"); 40 | 41 | done(); 42 | }); 43 | 44 | test("can figure out caller line", function(done) { 45 | 46 | var req = {}; 47 | var res = {}; 48 | var buf = ""; 49 | var line = ""; 50 | 51 | RequestLog.factory(function (level, id, _line, msg) { 52 | line = _line; 53 | buf += msg; 54 | })(req, res, function() {}); 55 | 56 | 57 | req.log.log("test"); 58 | 59 | assert.equal(buf, "test"); 60 | assert.equal(line, "Test.fn (/Users/juhomakinen/Development/node-scribe/test/requestlog.test.js:57:11)"); 61 | 62 | done(); 63 | }); 64 | 65 | test("can pass level correctly", function(done) { 66 | 67 | var req = {}; 68 | var res = {}; 69 | var levels = []; 70 | 71 | 72 | RequestLog.factory(function (level, id, _line, msg) { 73 | levels.push(level); 74 | })(req, res, function() {}); 75 | 76 | req.log.log("test"); 77 | req.log.info("test"); 78 | req.log.warn("test"); 79 | req.log.error("test"); 80 | req.log.critical("test"); 81 | 82 | 83 | assert.equal(levels[0], 7); 84 | assert.equal(levels[1], 6); 85 | assert.equal(levels[2], 4); 86 | assert.equal(levels[3], 3); 87 | assert.equal(levels[4], 2); 88 | 89 | done(); 90 | }); 91 | 92 | test("can has unique id", function(done) { 93 | 94 | var req = {}; 95 | var res = {}; 96 | var levels = []; 97 | 98 | 99 | RequestLog.factory(function (level, id, _line, msg) { 100 | levels.push(level); 101 | })(req, res, function() {}); 102 | 103 | 104 | 105 | assert.ok(req.log.id); 106 | 107 | done(); 108 | }); 109 | 110 | -------------------------------------------------------------------------------- /test/scribe.test.js: -------------------------------------------------------------------------------- 1 | var assert = require('assert'); 2 | var Scribe = require('../lib/scribe').Scribe; 3 | var scribeServer = require('../test_utils/scribeserver'); 4 | 5 | 6 | module.exports = { 7 | 'test construct': function() { 8 | var scribe = new Scribe("localhost", 8988); 9 | }, 10 | 'test connection opening' : function() { 11 | var server = scribeServer.createServer(); 12 | server.listen(8988); 13 | var scribe = new Scribe("localhost", 8988); 14 | scribe.open(function(err, client) { 15 | scribe.close(); 16 | setTimeout(function() { 17 | server.close(); 18 | }, 500); 19 | }); 20 | 21 | }, 22 | 'test sending data' : function() { 23 | var server = scribeServer.createServer(); 24 | server.on('log', function(entry) { 25 | assert.equal(entry.length, 1, "Should have received one entry"); 26 | assert.equal(entry[0].category, "foogroup"); 27 | assert.equal(entry[0].message, "barmessage"); 28 | setTimeout(function() { 29 | scribe.close(); 30 | server.close(); 31 | }, 500); 32 | }); 33 | server.listen(8989); 34 | var scribe = new Scribe("localhost", 8989); 35 | scribe.open(function(err, client) { 36 | scribe.send("foogroup", "barmessage"); 37 | 38 | }); 39 | }, 40 | 'test queuing data' : function() { 41 | var server = scribeServer.createServer(); 42 | server.on('log', function(entry) { 43 | assert.equal(entry.length, 6, "Should have received 6 entries"); 44 | setTimeout(function() { 45 | scribe.close(); 46 | server.close(); 47 | }, 500); 48 | }); 49 | server.listen(8990); 50 | var scribe = new Scribe("localhost", 8990); 51 | scribe.send("foogroup1", "barmessage"); 52 | scribe.send("foogroup2", "barmessage"); 53 | scribe.send("foogroup3", "barmessage"); 54 | scribe.send("foogroup4", "barmessage"); 55 | scribe.send("foogroup5", "barmessage"); 56 | scribe.send("foogroup6", "barmessage"); 57 | scribe.open(function(err, client) { 58 | 59 | 60 | }); 61 | } 62 | }; 63 | -------------------------------------------------------------------------------- /test_utils/scribeserver.js: -------------------------------------------------------------------------------- 1 | var thrift = require('thrift'), 2 | scribe = require('../lib/gen-nodejs/scribe'), 3 | ttypes = require('../lib/gen-nodejs/scribe_types'); 4 | 5 | 6 | var createServer = exports.createServer = function() { 7 | var server = thrift.createServer(scribe, { 8 | Log: function(entry, callback) { 9 | console.log("Server received ", entry); 10 | server.emit('log', entry); 11 | callback(0); 12 | } 13 | }); 14 | return server; 15 | }; 16 | 17 | 18 | if(!module.parent) { 19 | var server = createServer(); 20 | server.listen(1463); 21 | console.log("Started in port 1463"); 22 | } --------------------------------------------------------------------------------