-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement base browser-side logging system (#144107)
* start refactoring and moving stuff around * add abstraction for BaseLogger * plug logging into core system * add logger factory to plugin init context * add unit tests for browser package * add more unit tests * [CI] Auto-commit changed files from 'node scripts/generate codeowners' * fix mock * add mocks, update system tests * update files due to merge * [CI] Auto-commit changed files from 'node scripts/generate codeowners' * update readme and package * remove chalk usages from client-side * add plugin context tests * [CI] Auto-commit changed files from 'node scripts/eslint --no-cache --fix' * fix new packages Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
- Loading branch information
1 parent
fd6047b
commit 2fb12fb
Showing
80 changed files
with
2,756 additions
and
129 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
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
114 changes: 114 additions & 0 deletions
114
packages/core/logging/core-logging-browser-internal/BUILD.bazel
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 |
---|---|---|
@@ -0,0 +1,114 @@ | ||
load("@npm//@bazel/typescript:index.bzl", "ts_config") | ||
load("@build_bazel_rules_nodejs//:index.bzl", "js_library") | ||
load("//src/dev/bazel:index.bzl", "jsts_transpiler", "pkg_npm", "pkg_npm_types", "ts_project") | ||
|
||
PKG_DIRNAME = "core-logging-browser-internal" | ||
PKG_REQUIRE_NAME = "@kbn/core-logging-browser-internal" | ||
|
||
SOURCE_FILES = glob( | ||
[ | ||
"**/*.ts", | ||
"**/*.tsx", | ||
], | ||
exclude = [ | ||
"**/*.config.js", | ||
"**/*.mock.*", | ||
"**/*.test.*", | ||
"**/*.stories.*", | ||
"**/__snapshots__/**", | ||
"**/integration_tests/**", | ||
"**/mocks/**", | ||
"**/scripts/**", | ||
"**/storybook/**", | ||
"**/test_fixtures/**", | ||
"**/test_helpers/**", | ||
], | ||
) | ||
|
||
SRCS = SOURCE_FILES | ||
|
||
filegroup( | ||
name = "srcs", | ||
srcs = SRCS, | ||
) | ||
|
||
NPM_MODULE_EXTRA_FILES = [ | ||
"package.json", | ||
] | ||
|
||
RUNTIME_DEPS = [ | ||
"//packages/core/logging/core-logging-common-internal", | ||
] | ||
|
||
TYPES_DEPS = [ | ||
"@npm//@types/node", | ||
"@npm//@types/jest", | ||
"//packages/kbn-logging:npm_module_types", | ||
"//packages/core/logging/core-logging-common-internal:npm_module_types", | ||
] | ||
|
||
jsts_transpiler( | ||
name = "target_node", | ||
srcs = SRCS, | ||
build_pkg_name = package_name(), | ||
) | ||
|
||
jsts_transpiler( | ||
name = "target_web", | ||
srcs = SRCS, | ||
build_pkg_name = package_name(), | ||
web = True, | ||
) | ||
|
||
ts_config( | ||
name = "tsconfig", | ||
src = "tsconfig.json", | ||
deps = [ | ||
"//:tsconfig.base.json", | ||
"//:tsconfig.bazel.json", | ||
], | ||
) | ||
|
||
ts_project( | ||
name = "tsc_types", | ||
args = ['--pretty'], | ||
srcs = SRCS, | ||
deps = TYPES_DEPS, | ||
declaration = True, | ||
emit_declaration_only = True, | ||
out_dir = "target_types", | ||
tsconfig = ":tsconfig", | ||
) | ||
|
||
js_library( | ||
name = PKG_DIRNAME, | ||
srcs = NPM_MODULE_EXTRA_FILES, | ||
deps = RUNTIME_DEPS + [":target_node", ":target_web"], | ||
package_name = PKG_REQUIRE_NAME, | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
js_library( | ||
name = "npm_module_types", | ||
srcs = NPM_MODULE_EXTRA_FILES, | ||
deps = RUNTIME_DEPS + [":target_node", ":target_web", ":tsc_types"], | ||
package_name = PKG_REQUIRE_NAME, | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
pkg_npm( | ||
name = "npm_module", | ||
deps = [":" + PKG_DIRNAME], | ||
) | ||
|
||
filegroup( | ||
name = "build", | ||
srcs = [":npm_module"], | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
pkg_npm( | ||
name = "build_types", | ||
deps = [":npm_module_types"], | ||
visibility = ["//visibility:public"], | ||
) |
3 changes: 3 additions & 0 deletions
3
packages/core/logging/core-logging-browser-internal/README.md
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# @kbn/core-logging-browser-internal | ||
|
||
This package contains the internal types and implementation for Core's browser-side logging service. |
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
export { BaseLogger, BrowserLoggingSystem, type IBrowserLoggingSystem } from './src'; |
13 changes: 13 additions & 0 deletions
13
packages/core/logging/core-logging-browser-internal/jest.config.js
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
module.exports = { | ||
preset: '@kbn/test', | ||
rootDir: '../../../..', | ||
roots: ['<rootDir>/packages/core/logging/core-logging-browser-internal'], | ||
}; |
7 changes: 7 additions & 0 deletions
7
packages/core/logging/core-logging-browser-internal/kibana.jsonc
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"type": "shared-common", | ||
"id": "@kbn/core-logging-browser-internal", | ||
"owner": "@elastic/kibana-core", | ||
"runtimeDeps": [], | ||
"typeDeps": [], | ||
} |
10 changes: 10 additions & 0 deletions
10
packages/core/logging/core-logging-browser-internal/package.json
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"name": "@kbn/core-logging-browser-internal", | ||
"private": true, | ||
"version": "1.0.0", | ||
"main": "./target_node/index.js", | ||
"browser": "./target_web/index.js", | ||
"author": "Kibana Core", | ||
"license": "SSPL-1.0 OR Elastic License 2.0", | ||
"types": "./target_types/index.d.ts" | ||
} |
56 changes: 56 additions & 0 deletions
56
packages/core/logging/core-logging-browser-internal/src/appenders/console_appender.test.ts
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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { LogRecord, LogLevel } from '@kbn/logging'; | ||
import { ConsoleAppender } from './console_appender'; | ||
|
||
test('`append()` correctly formats records and pushes them to console.', () => { | ||
jest.spyOn(global.console, 'log').mockImplementation(() => { | ||
// noop | ||
}); | ||
|
||
const records: LogRecord[] = [ | ||
{ | ||
context: 'context-1', | ||
level: LogLevel.All, | ||
message: 'message-1', | ||
timestamp: new Date(), | ||
pid: 5355, | ||
}, | ||
{ | ||
context: 'context-2', | ||
level: LogLevel.Trace, | ||
message: 'message-2', | ||
timestamp: new Date(), | ||
pid: 5355, | ||
}, | ||
{ | ||
context: 'context-3', | ||
error: new Error('Error'), | ||
level: LogLevel.Fatal, | ||
message: 'message-3', | ||
timestamp: new Date(), | ||
pid: 5355, | ||
}, | ||
]; | ||
|
||
const appender = new ConsoleAppender({ | ||
format(record) { | ||
return `mock-${JSON.stringify(record)}`; | ||
}, | ||
}); | ||
|
||
for (const record of records) { | ||
appender.append(record); | ||
// eslint-disable-next-line no-console | ||
expect(console.log).toHaveBeenCalledWith(`mock-${JSON.stringify(record)}`); | ||
} | ||
|
||
// eslint-disable-next-line no-console | ||
expect(console.log).toHaveBeenCalledTimes(records.length); | ||
}); |
38 changes: 38 additions & 0 deletions
38
packages/core/logging/core-logging-browser-internal/src/appenders/console_appender.ts
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import type { Layout, LogRecord, DisposableAppender } from '@kbn/logging'; | ||
|
||
/** | ||
* | ||
* Appender that formats all the `LogRecord` instances it receives and logs them via built-in `console`. | ||
* @internal | ||
*/ | ||
export class ConsoleAppender implements DisposableAppender { | ||
/** | ||
* Creates ConsoleAppender instance. | ||
* @param layout Instance of `Layout` sub-class responsible for `LogRecord` formatting. | ||
*/ | ||
constructor(private readonly layout: Layout) {} | ||
|
||
/** | ||
* Formats specified `record` and logs it via built-in `console`. | ||
* @param record `LogRecord` instance to be logged. | ||
*/ | ||
public append(record: LogRecord) { | ||
// eslint-disable-next-line no-console | ||
console.log(this.layout.format(record)); | ||
} | ||
|
||
/** | ||
* Disposes `ConsoleAppender`. | ||
*/ | ||
public dispose() { | ||
// noop | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
packages/core/logging/core-logging-browser-internal/src/appenders/index.ts
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
export { ConsoleAppender } from './console_appender'; |
10 changes: 10 additions & 0 deletions
10
packages/core/logging/core-logging-browser-internal/src/index.ts
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
export { BaseLogger } from './logger'; | ||
export { BrowserLoggingSystem, type IBrowserLoggingSystem } from './logging_system'; |
Oops, something went wrong.