forked from gravitational/teleport
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Capture tshd logs (gravitational#853)
- Loading branch information
Showing
15 changed files
with
75 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,39 @@ | ||
import * as types from 'teleterm/types'; | ||
|
||
export class DefaultService { | ||
createLogger(loggerName: string): types.Logger { | ||
const name = loggerName; | ||
|
||
const log = (level = 'log', ...args) => { | ||
console[level](`%c[${name}]`, `color: blue;`, ...args); | ||
}; | ||
|
||
return { | ||
warn(...args: any[]) { | ||
log('warn', ...args); | ||
}, | ||
|
||
info(...args: any[]) { | ||
log('info', ...args); | ||
}, | ||
|
||
error(...args: any[]) { | ||
log('error', ...args); | ||
}, | ||
}; | ||
} | ||
} | ||
|
||
export default class Logger { | ||
private static service: types.LoggerService; | ||
private logger: types.Logger; | ||
|
||
private static service = new DefaultService(); | ||
|
||
constructor(context = '') { | ||
this.logger = Logger.service.createLogger(context); | ||
} | ||
// The Logger can be initialized in the top-level scope, but any actual | ||
// logging cannot be done in that scope, because we cannot guarantee that | ||
// Logger.init has already been called | ||
constructor(private context = '') {} | ||
|
||
warn(message: string, ...args: any[]) { | ||
this.logger.warn(message, ...args); | ||
this.getLogger().warn(message, ...args); | ||
} | ||
|
||
info(message: string, ...args: any[]) { | ||
this.logger.info(message, ...args); | ||
this.getLogger().info(message, ...args); | ||
} | ||
|
||
error(message: string, ...args: any[]) { | ||
this.logger.error(message, ...args); | ||
this.getLogger().error(message, ...args); | ||
} | ||
|
||
static init(service: types.LoggerService) { | ||
Logger.service = service; | ||
} | ||
|
||
private getLogger(): types.Logger { | ||
if (!this.logger) { | ||
if (!Logger.service) { | ||
throw new Error('Logger is not initialized'); | ||
} | ||
|
||
this.logger = Logger.service.createLogger(this.context); | ||
} | ||
|
||
return this.logger; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,12 @@ | ||
import { Stream } from 'stream'; | ||
|
||
export interface Logger { | ||
error(...args: unknown[]): void; | ||
warn(...args: unknown[]): void; | ||
info(...args: unknown[]): void; | ||
} | ||
|
||
export interface LoggerService { | ||
pipeProcessOutputIntoLogger(stream: Stream): void; | ||
createLogger(context: string): Logger; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5690,7 +5690,7 @@ delegates@^1.0.0: | |
depd@^1.1.2, depd@~1.1.2: | ||
version "1.1.2" | ||
resolved "https://registry.yarnpkg.com/depd/-/depd-1.1.2.tgz#9bcd52e14c097763e749b274c4346ed2e560b5a9" | ||
integrity sha1-m81S4UwJd2PnSbJ0xDRu0uVgtak= | ||
integrity sha512-7emPTl6Dpo6JRXOXjLRxck+FlLRX5847cLKEn00PLAgc3g2hTZZgr+e4c2v6QpSmLeFP3n5yUo7ft6avBK/5jQ== | ||
|
||
des.js@^1.0.0: | ||
version "1.0.1" | ||
|
@@ -7983,7 +7983,7 @@ human-signals@^2.1.0: | |
humanize-ms@^1.2.1: | ||
version "1.2.1" | ||
resolved "https://registry.yarnpkg.com/humanize-ms/-/humanize-ms-1.2.1.tgz#c46e3159a293f6b896da29316d8b6fe8bb79bbed" | ||
integrity sha1-xG4xWaKT9riW2ikxbYtv6Lt5u+0= | ||
integrity sha512-Fl70vYtsAFb/C06PTS9dZBo7ihau+Tu/DNCk/OyHhea07S+aeMWpFFkUaXRa8fI+ScZbEI8dfSxwY7gxZ9SAVQ== | ||
dependencies: | ||
ms "^2.0.0" | ||
|
||
|
@@ -8392,7 +8392,7 @@ is-installed-globally@^0.4.0: | |
is-lambda@^1.0.1: | ||
version "1.0.1" | ||
resolved "https://registry.yarnpkg.com/is-lambda/-/is-lambda-1.0.1.tgz#3d9877899e6a53efc0160504cde15f82e6f061d5" | ||
integrity sha1-PZh3iZ5qU+/AFgUEzeFfgubwYdU= | ||
integrity sha512-z7CMFGNrENq5iFB9Bqo64Xk6Y9sg+epq1myIcdHaGnbMTYOxvzsEtdYqQUylB7LxfkvgrrjP32T6Ywciio9UIQ== | ||
|
||
is-map@^2.0.2: | ||
version "2.0.2" | ||
|
@@ -12711,6 +12711,11 @@ split-string@^3.0.1, split-string@^3.0.2: | |
dependencies: | ||
extend-shallow "^3.0.0" | ||
|
||
[email protected]: | ||
version "4.1.0" | ||
resolved "https://registry.yarnpkg.com/split2/-/split2-4.1.0.tgz#101907a24370f85bb782f08adaabe4e281ecf809" | ||
integrity sha512-VBiJxFkxiXRlUIeyMQi8s4hgvKCSjtknJv/LVYbrgALPwf5zSKmEwV9Lst25AkvMDnvxODugjdl6KZgwKM1WYQ== | ||
|
||
sprintf-js@^1.1.2: | ||
version "1.1.2" | ||
resolved "https://registry.yarnpkg.com/sprintf-js/-/sprintf-js-1.1.2.tgz#da1765262bf8c0f571749f2ad6c26300207ae673" | ||
|