@@ -25,14 +25,13 @@ var util = require('util');
2525var semver = require ( 'semver' ) ;
2626var _ = require ( 'lodash' ) ;
2727var metadata = require ( 'gcp-metadata' ) ;
28+ var common = require ( '@google-cloud/common' ) ;
2829
2930var v8debugapi = require ( './v8debugapi.js' ) ;
3031var Debuggee = require ( '../debuggee.js' ) ;
3132var DebugletApi = require ( '../controller.js' ) ;
3233var defaultConfig = require ( './config.js' ) ;
3334var scanner = require ( './scanner.js' ) ;
34- var common = require ( '@google/cloud-diagnostics-common' ) ;
35- var Logger = common . logger ;
3635var StatusMessage = require ( '../status-message.js' ) ;
3736var SourceMapper = require ( './sourcemapper.js' ) ;
3837var pjson = require ( '../../package.json' ) ;
@@ -44,6 +43,43 @@ var NODE_VERSION_MESSAGE = 'Node.js version not supported. Node.js 5.2.0 and ' +
4443var BREAKPOINT_ACTION_MESSAGE = 'The only currently supported breakpoint actions' +
4544 ' are CAPTURE and LOG.' ;
4645
46+ /**
47+ * Formats a breakpoint object prefixed with a provided message as a string
48+ * intended for logging.
49+ * @param {string } msg The message that prefixes the formatted breakpoint.
50+ * @param {Breakpoint } breakpoint The breakpoint to format.
51+ * @return {string } A formatted string.
52+ */
53+ var formatBreakpoint = function ( msg , breakpoint ) {
54+ var text = msg + util . format ( 'breakpoint id: %s,\n\tlocation: %s' ,
55+ breakpoint . id , util . inspect ( breakpoint . location ) ) ;
56+ if ( breakpoint . createdTime ) {
57+ var unixTime = parseInt ( breakpoint . createdTime . seconds , 10 ) ;
58+ var date = new Date ( unixTime * 1000 ) ; // to milliseconds.
59+ text += '\n\tcreatedTime: ' + date . toString ( ) ;
60+ }
61+ if ( breakpoint . condition ) {
62+ text += '\n\tcondition: ' + util . inspect ( breakpoint . condition ) ;
63+ }
64+ if ( breakpoint . expressions ) {
65+ text += '\n\texpressions: ' + util . inspect ( breakpoint . expressions ) ;
66+ }
67+ return text ;
68+ } ;
69+
70+ /**
71+ * Formats a map of breakpoint objects prefixed with a provided message as a
72+ * string intended for logging.
73+ * @param {string } msg The message that prefixes the formatted breakpoint.
74+ * @param {Object.<string, Breakpoint> } breakpoints A map of breakpoints.
75+ * @return {string } A formatted string.
76+ */
77+ var formatBreakpoints = function ( msg , breakpoints ) {
78+ return msg + Object . keys ( breakpoints ) . map ( function ( b ) {
79+ formatBreakpoint ( '' , b ) ;
80+ } ) . join ( '\n' ) ;
81+ } ;
82+
4783module . exports = Debuglet ;
4884
4985/**
@@ -80,8 +116,11 @@ function Debuglet(debug, config) {
80116 /** @private {boolean} */
81117 this . fetcherActive_ = false ;
82118
83- /** @private {Logger} */
84- this . logger_ = Logger . create ( this . config_ . logLevel , '@google-cloud/debug' ) ;
119+ /** @private {common.logger} */
120+ this . logger_ = new common . logger ( {
121+ level : common . logger . LEVELS [ this . config_ . logLevel ] ,
122+ tag : '@google-cloud/debug'
123+ } ) ;
85124
86125 /** @private {DebugletApi} */
87126 this . debugletApi_ = new DebugletApi ( this . debug_ ) ;
@@ -274,7 +313,7 @@ Debuglet.prototype.getProjectId_ = function(callback) {
274313 // to access the metadata service as a test for that.
275314 // TODO: change this to getProjectId in the future.
276315 metadata . project (
277- 'numeric- project-id' , function ( err , response , metadataProject ) {
316+ 'project-id' , function ( err , response , metadataProject ) {
278317 // We should get an error if we are not on GCP.
279318 var onGCP = ! err ;
280319
@@ -407,8 +446,8 @@ Debuglet.prototype.scheduleBreakpointFetch_ = function(seconds) {
407446 } ) ;
408447 that . updateActiveBreakpoints_ ( bps ) ;
409448 if ( Object . keys ( that . activeBreakpointMap_ ) . length ) {
410- that . logger_ . breakpoints ( Logger . INFO , 'Active Breakpoints:' ,
411- that . activeBreakpointMap_ ) ;
449+ that . logger_ . info ( formatBreakpoint ( 'Active Breakpoints: ' ,
450+ that . activeBreakpointMap_ ) ) ;
412451 }
413452 that . scheduleBreakpointFetch_ ( that . config_ . breakpointUpdateIntervalSec ) ;
414453 return ;
@@ -427,7 +466,8 @@ Debuglet.prototype.updateActiveBreakpoints_ = function(breakpoints) {
427466 var updatedBreakpointMap = this . convertBreakpointListToMap_ ( breakpoints ) ;
428467
429468 if ( breakpoints . length ) {
430- that . logger_ . breakpoints ( Logger . INFO , 'Server breakpoints:' , updatedBreakpointMap ) ;
469+ that . logger_ . info ( formatBreakpoints ( 'Server breakpoints: ' ,
470+ updatedBreakpointMap ) ) ;
431471 }
432472
433473 breakpoints . forEach ( function ( breakpoint ) {
0 commit comments