@google-cloud/profiler
Advanced tools
Comparing version 4.1.5 to 4.1.6
@@ -71,3 +71,3 @@ import { GoogleAuthOptions } from '@google-cloud/common'; | ||
initialBackoffMillis: number; | ||
backoffCapMillis: number | null; | ||
backoffCapMillis: number; | ||
backoffMultiplier: number; | ||
@@ -74,0 +74,0 @@ apiEndpoint: string; |
@@ -200,3 +200,21 @@ "use strict"; | ||
const { rss, heapTotal, heapUsed } = process.memoryUsage(); | ||
logger.debug(new Date().toISOString(), 'rss', (rss / (1024 * 1024)).toFixed(3), 'MiB,', 'heap total', (heapTotal / (1024 * 1024)).toFixed(3), 'MiB,', 'heap used', (heapUsed / (1024 * 1024)).toFixed(3), 'MiB,', 'heap profile collection rate', ((heapProfileCount * 1000) / (curTime - prevLogTime)).toFixed(3), 'profiles/s,', 'time profile collection rate', ((timeProfileCount * 1000) / (curTime - prevLogTime)).toFixed(3), 'profiles/s'); | ||
const debugInfo = [ | ||
new Date().toISOString(), | ||
'rss', | ||
(rss / (1024 * 1024)).toFixed(3), | ||
'MiB,', | ||
'heap total', | ||
(heapTotal / (1024 * 1024)).toFixed(3), | ||
'MiB,', | ||
'heap used', | ||
(heapUsed / (1024 * 1024)).toFixed(3), | ||
'MiB,', | ||
'heap profile collection rate', | ||
((heapProfileCount * 1000) / (curTime - prevLogTime)).toFixed(3), | ||
'profiles/s,', | ||
'time profile collection rate', | ||
((timeProfileCount * 1000) / (curTime - prevLogTime)).toFixed(3), | ||
'profiles/s', | ||
].map(v => v + ''); | ||
logger.debug(debugInfo.join(' ')); | ||
heapProfileCount = 0; | ||
@@ -203,0 +221,0 @@ timeProfileCount = 0; |
@@ -1,2 +0,12 @@ | ||
import * as consoleLogLevel from 'console-log-level'; | ||
export declare function createLogger(level?: number): Record<consoleLogLevel.LogLevelNames, (...args: any[]) => void>; | ||
export declare class Logger { | ||
readonly level?: number | undefined; | ||
private log; | ||
private severityThreshold; | ||
constructor(level?: number | undefined); | ||
debug(msg: string): void; | ||
info(msg: string): void; | ||
warn(msg: string): void; | ||
error(msg: string): void; | ||
private toOneLine; | ||
} | ||
export declare function createLogger(level?: number): Logger; |
@@ -16,35 +16,63 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createLogger = void 0; | ||
const consoleLogLevel = require("console-log-level"); | ||
exports.createLogger = exports.Logger = void 0; | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
const config_1 = require("./config"); | ||
const logging_min_1 = require("@google-cloud/logging-min"); | ||
const logging = new logging_min_1.Logging(); | ||
// migrating from 'console-log-level' package we keep | ||
// min and max log levels numeric interface used there | ||
const [MIN_LEVEL, MAX_LEVEL] = [0, 4]; | ||
logging.setProjectId().catch(err => { | ||
console.error(`failed to set logging project id ${err}`); | ||
}); | ||
logging.setDetectedResource().catch(err => { | ||
console.error(`failed to discover resource metadata ${err}`); | ||
}); | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
const pjson = require('../../package.json'); | ||
const LEVEL_NAMES = [ | ||
'fatal', | ||
'error', | ||
'warn', | ||
'info', | ||
'debug', | ||
'trace', | ||
]; | ||
function logLevelToName(level) { | ||
if (level === undefined) { | ||
level = config_1.defaultConfig.logLevel; | ||
class Logger { | ||
constructor(level) { | ||
this.level = level; | ||
if (level === undefined) { | ||
level = config_1.defaultConfig.logLevel; | ||
} | ||
if (level < MIN_LEVEL) { | ||
level = MIN_LEVEL; | ||
} | ||
else if (level > MAX_LEVEL) { | ||
level = MAX_LEVEL; | ||
} | ||
this.severityThreshold = level; | ||
this.log = logging.logSync(pjson.name); | ||
} | ||
else if (level < 0) { | ||
level = 0; | ||
debug(msg) { | ||
if (this.severityThreshold > 3) { | ||
this.log.debug(this.log.entry(this.toOneLine(msg))); | ||
} | ||
} | ||
else if (level > 4) { | ||
level = 4; | ||
info(msg) { | ||
if (this.severityThreshold > 2) { | ||
this.log.info(this.log.entry(this.toOneLine(msg))); | ||
} | ||
} | ||
return LEVEL_NAMES[level]; | ||
warn(msg) { | ||
if (this.severityThreshold > 1) { | ||
this.log.warning(this.log.entry(this.toOneLine(msg))); | ||
} | ||
} | ||
error(msg) { | ||
if (this.severityThreshold > 0) { | ||
this.log.error(this.log.entry(this.toOneLine(msg))); | ||
} | ||
} | ||
toOneLine(msg) { | ||
const temp = msg.replace('\r\n', '\\r\\n'); | ||
return temp.replace('\n', '\\n'); | ||
} | ||
} | ||
exports.Logger = Logger; | ||
function createLogger(level) { | ||
return consoleLogLevel({ | ||
stderr: true, | ||
prefix: pjson.name, | ||
level: logLevelToName(level), | ||
}); | ||
return new Logger(level); | ||
} | ||
exports.createLogger = createLogger; | ||
//# sourceMappingURL=logger.js.map |
@@ -7,2 +7,9 @@ # Changelog | ||
### [4.1.6](https://www.github.com/googleapis/cloud-profiler-nodejs/compare/v4.1.5...v4.1.6) (2021-12-20) | ||
### Bug Fixes | ||
* log to console using structured logging ([#780](https://www.github.com/googleapis/cloud-profiler-nodejs/issues/780)) ([6b96e00](https://www.github.com/googleapis/cloud-profiler-nodejs/commit/6b96e007418bd6074c2bf9de64df0742e6a6d4ae)) | ||
### [4.1.5](https://www.github.com/googleapis/cloud-profiler-nodejs/compare/v4.1.4...v4.1.5) (2021-10-06) | ||
@@ -9,0 +16,0 @@ |
{ | ||
"name": "@google-cloud/profiler", | ||
"version": "4.1.5", | ||
"version": "4.1.6", | ||
"description": "Adds support for Cloud Profiler to Node.js applications", | ||
@@ -32,2 +32,3 @@ "repository": "googleapis/cloud-profiler-nodejs", | ||
"@google-cloud/common": "^3.0.0", | ||
"@google-cloud/logging-min": "^9.6.3", | ||
"@types/console-log-level": "^1.4.0", | ||
@@ -51,6 +52,6 @@ "@types/semver": "^7.0.0", | ||
"@types/nock": "^10.0.0", | ||
"@types/node": "^14.0.0", | ||
"@types/node": "^16.0.0", | ||
"@types/pretty-ms": "^4.0.0", | ||
"@types/sinon": "^10.0.0", | ||
"@types/tmp": "0.2.1", | ||
"@types/tmp": "0.2.3", | ||
"c8": "^7.0.0", | ||
@@ -66,3 +67,3 @@ "codecov": "^3.0.0", | ||
"nock": "^13.0.0", | ||
"sinon": "^11.0.0", | ||
"sinon": "^12.0.0", | ||
"source-map": "^0.7.0", | ||
@@ -69,0 +70,0 @@ "tmp": "0.2.1", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1007659
17520
14
+ Added@google-cloud/logging-min@9.9.0(transitive)
+ Added@google-cloud/paginator@3.0.7(transitive)
+ Added@grpc/grpc-js@1.6.12(transitive)
+ Added@grpc/proto-loader@0.6.130.7.13(transitive)
+ Addedansi-styles@4.3.0(transitive)
+ Addedcliui@7.0.48.0.1(transitive)
+ Addedcolor-convert@2.0.1(transitive)
+ Addedcolor-name@1.1.4(transitive)
+ Addeddot-prop@6.0.1(transitive)
+ Addedee-first@1.1.1(transitive)
+ Addedescalade@3.2.0(transitive)
+ Addedeventid@2.0.1(transitive)
+ Addedget-caller-file@2.0.5(transitive)
+ Addedgoogle-gax@2.30.5(transitive)
+ Addedis-obj@2.0.0(transitive)
+ Addedis-stream-ended@0.1.4(transitive)
+ Addedlodash.camelcase@4.3.0(transitive)
+ Addedlong@5.2.3(transitive)
+ Addedobject-hash@3.0.0(transitive)
+ Addedon-finished@2.4.1(transitive)
+ Addedproto3-json-serializer@0.1.9(transitive)
+ Addedprotobufjs@6.11.37.4.0(transitive)
+ Addedpump@3.0.2(transitive)
+ Addedpumpify@2.0.1(transitive)
+ Addedrequire-directory@2.1.1(transitive)
+ Addedwrap-ansi@7.0.0(transitive)
+ Addedy18n@5.0.8(transitive)
+ Addedyargs@16.2.017.7.2(transitive)
+ Addedyargs-parser@20.2.921.1.1(transitive)