* Logs all messages to the Console API. * @param {!Entry} entry the entry to log.
(entry)
| 562 | * @param {!Entry} entry the entry to log. |
| 563 | */ |
| 564 | function consoleHandler(entry) { |
| 565 | if (typeof console === 'undefined' || !console) { |
| 566 | return |
| 567 | } |
| 568 | |
| 569 | var timestamp = new Date(entry.timestamp) |
| 570 | var msg = |
| 571 | '[' + |
| 572 | timestamp.getUTCFullYear() + |
| 573 | '-' + |
| 574 | pad(timestamp.getUTCMonth() + 1) + |
| 575 | '-' + |
| 576 | pad(timestamp.getUTCDate()) + |
| 577 | 'T' + |
| 578 | pad(timestamp.getUTCHours()) + |
| 579 | ':' + |
| 580 | pad(timestamp.getUTCMinutes()) + |
| 581 | ':' + |
| 582 | pad(timestamp.getUTCSeconds()) + |
| 583 | 'Z] ' + |
| 584 | '[' + |
| 585 | entry.level.name + |
| 586 | '] ' + |
| 587 | entry.message |
| 588 | |
| 589 | var level = entry.level.value |
| 590 | if (level >= Level.SEVERE.value) { |
| 591 | console.error(msg) |
| 592 | } else if (level >= Level.WARNING.value) { |
| 593 | console.warn(msg) |
| 594 | } else { |
| 595 | console.log(msg) |
| 596 | } |
| 597 | } |
| 598 | |
| 599 | /** |
| 600 | * Adds the console handler to the given logger. The console handler will log |