mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
Move server-side logging service to packages (#134438)
* Adapt LoggerConfigType to no longer inferred from config schema * creating the new empty packages * moving the public types to @kbn/core-logging-server * updating @kbn/core-logging-server bazel config * fix imports due to types moving to @kbn/core-logging-server * moving the concrete implementation to @kbn/core-logging-server-internal * updating @kbn/core-logging-server-internal bazel config * adapt @kbn/core-logging-server-internal test files * Move the mocks to @kbn/core-logging-server-mocks * Fix imports due to server and mock moving to packages * update generated doc * update READMEs * update tsdoc
This commit is contained in:
parent
4c506e4bfb
commit
a969d42ecf
172 changed files with 1011 additions and 512 deletions
|
@ -1,12 +0,0 @@
|
|||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [kibana-plugin-core-server](./kibana-plugin-core-server.md) > [AppenderConfigType](./kibana-plugin-core-server.appenderconfigtype.md)
|
||||
|
||||
## AppenderConfigType type
|
||||
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
export declare type AppenderConfigType = ConsoleAppenderConfig | FileAppenderConfig | RewriteAppenderConfig | RollingFileAppenderConfig;
|
||||
```
|
|
@ -4,7 +4,6 @@
|
|||
|
||||
## CoreSetup.logging property
|
||||
|
||||
[LoggingServiceSetup](./kibana-plugin-core-server.loggingservicesetup.md)
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ export interface CoreSetup<TPluginsStart extends object = object, TStart = unkno
|
|||
| [getStartServices](./kibana-plugin-core-server.coresetup.getstartservices.md) | StartServicesAccessor<TPluginsStart, TStart> | [StartServicesAccessor](./kibana-plugin-core-server.startservicesaccessor.md) |
|
||||
| [http](./kibana-plugin-core-server.coresetup.http.md) | HttpServiceSetup & { resources: HttpResources; } | [HttpServiceSetup](./kibana-plugin-core-server.httpservicesetup.md) |
|
||||
| [i18n](./kibana-plugin-core-server.coresetup.i18n.md) | I18nServiceSetup | [I18nServiceSetup](./kibana-plugin-core-server.i18nservicesetup.md) |
|
||||
| [logging](./kibana-plugin-core-server.coresetup.logging.md) | LoggingServiceSetup | [LoggingServiceSetup](./kibana-plugin-core-server.loggingservicesetup.md) |
|
||||
| [logging](./kibana-plugin-core-server.coresetup.logging.md) | LoggingServiceSetup | |
|
||||
| [metrics](./kibana-plugin-core-server.coresetup.metrics.md) | MetricsServiceSetup | [MetricsServiceSetup](./kibana-plugin-core-server.metricsservicesetup.md) |
|
||||
| [savedObjects](./kibana-plugin-core-server.coresetup.savedobjects.md) | SavedObjectsServiceSetup | [SavedObjectsServiceSetup](./kibana-plugin-core-server.savedobjectsservicesetup.md) |
|
||||
| [status](./kibana-plugin-core-server.coresetup.status.md) | StatusServiceSetup | [StatusServiceSetup](./kibana-plugin-core-server.statusservicesetup.md) |
|
||||
|
|
|
@ -1,12 +0,0 @@
|
|||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [kibana-plugin-core-server](./kibana-plugin-core-server.md) > [LoggerConfigType](./kibana-plugin-core-server.loggerconfigtype.md)
|
||||
|
||||
## LoggerConfigType type
|
||||
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
export declare type LoggerConfigType = TypeOf<typeof loggerSchema>;
|
||||
```
|
|
@ -1,11 +0,0 @@
|
|||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [kibana-plugin-core-server](./kibana-plugin-core-server.md) > [LoggerContextConfigInput](./kibana-plugin-core-server.loggercontextconfiginput.md) > [appenders](./kibana-plugin-core-server.loggercontextconfiginput.appenders.md)
|
||||
|
||||
## LoggerContextConfigInput.appenders property
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
appenders?: Record<string, AppenderConfigType> | Map<string, AppenderConfigType>;
|
||||
```
|
|
@ -1,11 +0,0 @@
|
|||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [kibana-plugin-core-server](./kibana-plugin-core-server.md) > [LoggerContextConfigInput](./kibana-plugin-core-server.loggercontextconfiginput.md) > [loggers](./kibana-plugin-core-server.loggercontextconfiginput.loggers.md)
|
||||
|
||||
## LoggerContextConfigInput.loggers property
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
loggers?: LoggerConfigType[];
|
||||
```
|
|
@ -1,20 +0,0 @@
|
|||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [kibana-plugin-core-server](./kibana-plugin-core-server.md) > [LoggerContextConfigInput](./kibana-plugin-core-server.loggercontextconfiginput.md)
|
||||
|
||||
## LoggerContextConfigInput interface
|
||||
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
export interface LoggerContextConfigInput
|
||||
```
|
||||
|
||||
## Properties
|
||||
|
||||
| Property | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| [appenders?](./kibana-plugin-core-server.loggercontextconfiginput.appenders.md) | Record<string, AppenderConfigType> \| Map<string, AppenderConfigType> | <i>(Optional)</i> |
|
||||
| [loggers?](./kibana-plugin-core-server.loggercontextconfiginput.loggers.md) | LoggerConfigType\[\] | <i>(Optional)</i> |
|
||||
|
|
@ -1,41 +0,0 @@
|
|||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [kibana-plugin-core-server](./kibana-plugin-core-server.md) > [LoggingServiceSetup](./kibana-plugin-core-server.loggingservicesetup.md) > [configure](./kibana-plugin-core-server.loggingservicesetup.configure.md)
|
||||
|
||||
## LoggingServiceSetup.configure() method
|
||||
|
||||
Customizes the logging config for the plugin's context.
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
configure(config$: Observable<LoggerContextConfigInput>): void;
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
| Parameter | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| config$ | Observable<LoggerContextConfigInput> | |
|
||||
|
||||
<b>Returns:</b>
|
||||
|
||||
void
|
||||
|
||||
## Remarks
|
||||
|
||||
Assumes that that the `context` property of the individual `logger` items emitted by `config$` are relative to the plugin's logging context (defaults to `plugins.<plugin_id>`<!-- -->).
|
||||
|
||||
## Example
|
||||
|
||||
Customize the configuration for the plugins.data.search context.
|
||||
|
||||
```ts
|
||||
core.logging.configure(
|
||||
of({
|
||||
appenders: new Map(),
|
||||
loggers: [{ name: 'search', appenders: ['default'] }]
|
||||
})
|
||||
)
|
||||
```
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [kibana-plugin-core-server](./kibana-plugin-core-server.md) > [LoggingServiceSetup](./kibana-plugin-core-server.loggingservicesetup.md)
|
||||
|
||||
## LoggingServiceSetup interface
|
||||
|
||||
Provides APIs to plugins for customizing the plugin's logger.
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
export interface LoggingServiceSetup
|
||||
```
|
||||
|
||||
## Methods
|
||||
|
||||
| Method | Description |
|
||||
| --- | --- |
|
||||
| [configure(config$)](./kibana-plugin-core-server.loggingservicesetup.configure.md) | Customizes the logging config for the plugin's context. |
|
||||
|
|
@ -108,8 +108,6 @@ The plugin integrates with the core system via lifecycle events: `setup`<!-- -->
|
|||
| [IUiSettingsClient](./kibana-plugin-core-server.iuisettingsclient.md) | Server-side client that provides access to the advanced settings stored in elasticsearch. The settings provide control over the behavior of the Kibana application. For example, a user can specify how to display numeric or date fields. Users can adjust the settings via Management UI. |
|
||||
| [KibanaRequestEvents](./kibana-plugin-core-server.kibanarequestevents.md) | Request events. |
|
||||
| [KibanaRequestRoute](./kibana-plugin-core-server.kibanarequestroute.md) | Request specific route information exposed to a handler. |
|
||||
| [LoggerContextConfigInput](./kibana-plugin-core-server.loggercontextconfiginput.md) | |
|
||||
| [LoggingServiceSetup](./kibana-plugin-core-server.loggingservicesetup.md) | Provides APIs to plugins for customizing the plugin's logger. |
|
||||
| [MetricsServiceSetup](./kibana-plugin-core-server.metricsservicesetup.md) | APIs to retrieves metrics gathered and exposed by the core platform. |
|
||||
| [NodesVersionCompatibility](./kibana-plugin-core-server.nodesversioncompatibility.md) | |
|
||||
| [OnPostAuthToolkit](./kibana-plugin-core-server.onpostauthtoolkit.md) | A tool set defining an outcome of OnPostAuth interceptor for incoming request. |
|
||||
|
@ -255,7 +253,6 @@ The plugin integrates with the core system via lifecycle events: `setup`<!-- -->
|
|||
| [AnalyticsServicePreboot](./kibana-plugin-core-server.analyticsservicepreboot.md) | Exposes the public APIs of the AnalyticsClient during the preboot phase |
|
||||
| [AnalyticsServiceSetup](./kibana-plugin-core-server.analyticsservicesetup.md) | Exposes the public APIs of the AnalyticsClient during the setup phase. |
|
||||
| [AnalyticsServiceStart](./kibana-plugin-core-server.analyticsservicestart.md) | Exposes the public APIs of the AnalyticsClient during the start phase |
|
||||
| [AppenderConfigType](./kibana-plugin-core-server.appenderconfigtype.md) | |
|
||||
| [AuthenticationHandler](./kibana-plugin-core-server.authenticationhandler.md) | See [AuthToolkit](./kibana-plugin-core-server.authtoolkit.md)<!-- -->. |
|
||||
| [AuthHeaders](./kibana-plugin-core-server.authheaders.md) | Auth Headers map |
|
||||
| [AuthResult](./kibana-plugin-core-server.authresult.md) | |
|
||||
|
@ -287,7 +284,6 @@ The plugin integrates with the core system via lifecycle events: `setup`<!-- -->
|
|||
| [KibanaResponseFactory](./kibana-plugin-core-server.kibanaresponsefactory.md) | Creates an object containing request response payload, HTTP headers, error details, and other data transmitted to the client. |
|
||||
| [KnownHeaders](./kibana-plugin-core-server.knownheaders.md) | Set of well-known HTTP headers. |
|
||||
| [LifecycleResponseFactory](./kibana-plugin-core-server.lifecycleresponsefactory.md) | Creates an object containing redirection or error response with error details, HTTP headers, and other data transmitted to the client. |
|
||||
| [LoggerConfigType](./kibana-plugin-core-server.loggerconfigtype.md) | |
|
||||
| [MakeUsageFromSchema](./kibana-plugin-core-server.makeusagefromschema.md) | List of configuration values that will be exposed to usage collection. If parent node or actual config path is set to <code>true</code> then the actual value of these configs will be reoprted. If parent node or actual config path is set to <code>false</code> then the config will be reported as \[redacted\]. |
|
||||
| [MetricsServiceStart](./kibana-plugin-core-server.metricsservicestart.md) | APIs to retrieves metrics gathered and exposed by the core platform. |
|
||||
| [MutatingOperationRefreshSetting](./kibana-plugin-core-server.mutatingoperationrefreshsetting.md) | Elasticsearch Refresh setting for mutating operation |
|
||||
|
|
|
@ -166,6 +166,9 @@
|
|||
"@kbn/core-injected-metadata-browser-internal": "link:bazel-bin/packages/core/injected-metadata/core-injected-metadata-browser-internal",
|
||||
"@kbn/core-injected-metadata-browser-mocks": "link:bazel-bin/packages/core/injected-metadata/core-injected-metadata-browser-mocks",
|
||||
"@kbn/core-injected-metadata-common-internal": "link:bazel-bin/packages/core/injected-metadata/core-injected-metadata-common-internal",
|
||||
"@kbn/core-logging-server": "link:bazel-bin/packages/core/logging/core-logging-server",
|
||||
"@kbn/core-logging-server-internal": "link:bazel-bin/packages/core/logging/core-logging-server-internal",
|
||||
"@kbn/core-logging-server-mocks": "link:bazel-bin/packages/core/logging/core-logging-server-mocks",
|
||||
"@kbn/core-theme-browser": "link:bazel-bin/packages/core/theme/core-theme-browser",
|
||||
"@kbn/core-theme-browser-internal": "link:bazel-bin/packages/core/theme/core-theme-browser-internal",
|
||||
"@kbn/core-theme-browser-mocks": "link:bazel-bin/packages/core/theme/core-theme-browser-mocks",
|
||||
|
@ -685,6 +688,9 @@
|
|||
"@types/kbn__core-injected-metadata-browser-internal": "link:bazel-bin/packages/core/injected-metadata/core-injected-metadata-browser-internal/npm_module_types",
|
||||
"@types/kbn__core-injected-metadata-browser-mocks": "link:bazel-bin/packages/core/injected-metadata/core-injected-metadata-browser-mocks/npm_module_types",
|
||||
"@types/kbn__core-injected-metadata-common-internal": "link:bazel-bin/packages/core/injected-metadata/core-injected-metadata-common-internal/npm_module_types",
|
||||
"@types/kbn__core-logging-server": "link:bazel-bin/packages/core/logging/core-logging-server/npm_module_types",
|
||||
"@types/kbn__core-logging-server-internal": "link:bazel-bin/packages/core/logging/core-logging-server-internal/npm_module_types",
|
||||
"@types/kbn__core-logging-server-mocks": "link:bazel-bin/packages/core/logging/core-logging-server-mocks/npm_module_types",
|
||||
"@types/kbn__core-public-internal-base": "link:bazel-bin/packages/core/public/internal-base/npm_module_types",
|
||||
"@types/kbn__core-server-internal-base": "link:bazel-bin/packages/core/server/internal-base/npm_module_types",
|
||||
"@types/kbn__core-theme-browser": "link:bazel-bin/packages/core/theme/core-theme-browser/npm_module_types",
|
||||
|
|
|
@ -33,6 +33,9 @@ filegroup(
|
|||
"//packages/core/injected-metadata/core-injected-metadata-browser-mocks:build",
|
||||
"//packages/core/injected-metadata/core-injected-metadata-browser:build",
|
||||
"//packages/core/injected-metadata/core-injected-metadata-common-internal:build",
|
||||
"//packages/core/logging/core-logging-server-internal:build",
|
||||
"//packages/core/logging/core-logging-server-mocks:build",
|
||||
"//packages/core/logging/core-logging-server:build",
|
||||
"//packages/core/theme/core-theme-browser-internal:build",
|
||||
"//packages/core/theme/core-theme-browser-mocks:build",
|
||||
"//packages/core/theme/core-theme-browser:build",
|
||||
|
@ -177,6 +180,9 @@ filegroup(
|
|||
"//packages/core/injected-metadata/core-injected-metadata-browser-mocks:build_types",
|
||||
"//packages/core/injected-metadata/core-injected-metadata-browser:build_types",
|
||||
"//packages/core/injected-metadata/core-injected-metadata-common-internal:build_types",
|
||||
"//packages/core/logging/core-logging-server-internal:build_types",
|
||||
"//packages/core/logging/core-logging-server-mocks:build_types",
|
||||
"//packages/core/logging/core-logging-server:build_types",
|
||||
"//packages/core/theme/core-theme-browser-internal:build_types",
|
||||
"//packages/core/theme/core-theme-browser-mocks:build_types",
|
||||
"//packages/core/theme/core-theme-browser:build_types",
|
||||
|
|
108
packages/core/logging/core-logging-server-internal/BUILD.bazel
Normal file
108
packages/core/logging/core-logging-server-internal/BUILD.bazel
Normal file
|
@ -0,0 +1,108 @@
|
|||
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-server-internal"
|
||||
PKG_REQUIRE_NAME = "@kbn/core-logging-server-internal"
|
||||
|
||||
SOURCE_FILES = glob(
|
||||
[
|
||||
"src/**/*.ts",
|
||||
],
|
||||
exclude = [
|
||||
"**/*.test.*",
|
||||
],
|
||||
)
|
||||
|
||||
SRCS = SOURCE_FILES
|
||||
|
||||
filegroup(
|
||||
name = "srcs",
|
||||
srcs = SRCS,
|
||||
)
|
||||
|
||||
NPM_MODULE_EXTRA_FILES = [
|
||||
"package.json",
|
||||
]
|
||||
|
||||
RUNTIME_DEPS = [
|
||||
"@npm//lodash",
|
||||
"@npm//moment-timezone",
|
||||
"@npm//elastic-apm-node",
|
||||
"//packages/elastic-safer-lodash-set",
|
||||
"//packages/kbn-config-schema",
|
||||
]
|
||||
|
||||
TYPES_DEPS = [
|
||||
"@npm//@types/node",
|
||||
"@npm//@types/jest",
|
||||
"@npm//@types/lodash",
|
||||
"@npm//@types/moment-timezone",
|
||||
"@npm//elastic-apm-node",
|
||||
"//packages/elastic-safer-lodash-set:npm_module_types",
|
||||
"//packages/kbn-logging:npm_module_types",
|
||||
"//packages/kbn-config-schema:npm_module_types",
|
||||
"//packages/core/base/core-base-server-internal:npm_module_types",
|
||||
"//packages/core/logging/core-logging-server:npm_module_types",
|
||||
]
|
||||
|
||||
jsts_transpiler(
|
||||
name = "target_node",
|
||||
srcs = SRCS,
|
||||
build_pkg_name = package_name(),
|
||||
)
|
||||
|
||||
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",
|
||||
root_dir = "src",
|
||||
tsconfig = ":tsconfig",
|
||||
)
|
||||
|
||||
js_library(
|
||||
name = PKG_DIRNAME,
|
||||
srcs = NPM_MODULE_EXTRA_FILES,
|
||||
deps = RUNTIME_DEPS + [":target_node"],
|
||||
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_types(
|
||||
name = "npm_module_types",
|
||||
srcs = SRCS,
|
||||
deps = [":tsc_types"],
|
||||
package_name = PKG_REQUIRE_NAME,
|
||||
tsconfig = ":tsconfig",
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "build_types",
|
||||
srcs = [":npm_module_types"],
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
|
@ -0,0 +1,3 @@
|
|||
# @kbn/core-logging-server-internal
|
||||
|
||||
This package contains the internal types and implementation for Core's server-side logging service.
|
|
@ -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/jest_node',
|
||||
rootDir: '../../../..',
|
||||
roots: ['<rootDir>/packages/core/logging/core-logging-server-internal'],
|
||||
};
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"name": "@kbn/core-logging-server-internal",
|
||||
"private": true,
|
||||
"version": "1.0.0",
|
||||
"main": "./target_node/index.js",
|
||||
"license": "SSPL-1.0 OR Elastic License 2.0"
|
||||
}
|
|
@ -9,15 +9,13 @@
|
|||
import { schema } from '@kbn/config-schema';
|
||||
import { assertNever } from '@kbn/std';
|
||||
import { DisposableAppender } from '@kbn/logging';
|
||||
import type { AppenderConfigType } from '@kbn/core-logging-server';
|
||||
|
||||
import { Layouts } from '../layouts/layouts';
|
||||
import { ConsoleAppender, ConsoleAppenderConfig } from './console/console_appender';
|
||||
import { FileAppender, FileAppenderConfig } from './file/file_appender';
|
||||
import { RewriteAppender, RewriteAppenderConfig } from './rewrite/rewrite_appender';
|
||||
import {
|
||||
RollingFileAppender,
|
||||
RollingFileAppenderConfig,
|
||||
} from './rolling_file/rolling_file_appender';
|
||||
import { ConsoleAppender } from './console/console_appender';
|
||||
import { FileAppender } from './file/file_appender';
|
||||
import { RewriteAppender } from './rewrite/rewrite_appender';
|
||||
import { RollingFileAppender } from './rolling_file/rolling_file_appender';
|
||||
|
||||
/**
|
||||
* Config schema for validting the shape of the `appenders` key in in {@link LoggerContextConfigType} or
|
||||
|
@ -32,13 +30,6 @@ export const appendersSchema = schema.oneOf([
|
|||
RollingFileAppender.configSchema,
|
||||
]);
|
||||
|
||||
/** @public */
|
||||
export type AppenderConfigType =
|
||||
| ConsoleAppenderConfig
|
||||
| FileAppenderConfig
|
||||
| RewriteAppenderConfig
|
||||
| RollingFileAppenderConfig;
|
||||
|
||||
/** @internal */
|
||||
export class Appenders {
|
||||
public static configSchema = appendersSchema;
|
|
@ -8,15 +8,10 @@
|
|||
|
||||
import { schema } from '@kbn/config-schema';
|
||||
import { Layout, LogRecord, DisposableAppender } from '@kbn/logging';
|
||||
import { Layouts, LayoutConfigType } from '../../layouts/layouts';
|
||||
import { Layouts } from '../../layouts/layouts';
|
||||
|
||||
const { literal, object } = schema;
|
||||
|
||||
export interface ConsoleAppenderConfig {
|
||||
type: 'console';
|
||||
layout: LayoutConfigType;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Appender that formats all the `LogRecord` instances it receives and logs them via built-in `console`.
|
|
@ -11,13 +11,7 @@ import { LogRecord, Layout, DisposableAppender } from '@kbn/logging';
|
|||
import { createWriteStream, WriteStream, mkdirSync } from 'fs';
|
||||
import { dirname } from 'path';
|
||||
|
||||
import { Layouts, LayoutConfigType } from '../../layouts/layouts';
|
||||
|
||||
export interface FileAppenderConfig {
|
||||
type: 'file';
|
||||
layout: LayoutConfigType;
|
||||
fileName: string;
|
||||
}
|
||||
import { Layouts } from '../../layouts/layouts';
|
||||
|
||||
/**
|
||||
* Appender that formats all the `LogRecord` instances it receives and writes them to the specified file.
|
|
@ -7,17 +7,12 @@
|
|||
*/
|
||||
|
||||
import { assertNever } from '@kbn/std';
|
||||
import type { RewritePolicyConfig } from '@kbn/core-logging-server';
|
||||
import { RewritePolicy } from './policy';
|
||||
import { MetaRewritePolicy, MetaRewritePolicyConfig, metaRewritePolicyConfigSchema } from './meta';
|
||||
import { MetaRewritePolicy, metaRewritePolicyConfigSchema } from './meta';
|
||||
|
||||
export type { RewritePolicy };
|
||||
|
||||
/**
|
||||
* Available rewrite policies which specify what part of a {@link LogRecord}
|
||||
* can be modified.
|
||||
*/
|
||||
export type RewritePolicyConfig = MetaRewritePolicyConfig;
|
||||
|
||||
export const rewritePolicyConfigSchema = metaRewritePolicyConfigSchema;
|
||||
|
||||
export const createRewritePolicy = (config: RewritePolicyConfig): RewritePolicy => {
|
|
@ -7,5 +7,3 @@
|
|||
*/
|
||||
|
||||
export { MetaRewritePolicy, metaRewritePolicyConfigSchema } from './meta_policy';
|
||||
|
||||
export type { MetaRewritePolicyConfig } from './meta_policy';
|
|
@ -7,7 +7,8 @@
|
|||
*/
|
||||
|
||||
import { LogRecord, LogLevel, LogMeta } from '@kbn/logging';
|
||||
import { MetaRewritePolicy, MetaRewritePolicyConfig } from './meta_policy';
|
||||
import type { MetaRewritePolicyConfig } from '@kbn/core-logging-server';
|
||||
import { MetaRewritePolicy } from './meta_policy';
|
||||
|
||||
describe('MetaRewritePolicy', () => {
|
||||
const createPolicy = (
|
|
@ -11,33 +11,9 @@ import { LogRecord } from '@kbn/logging';
|
|||
import { set } from '@elastic/safer-lodash-set';
|
||||
import { has, unset } from 'lodash';
|
||||
import { assertNever } from '@kbn/std';
|
||||
import type { MetaRewritePolicyConfig } from '@kbn/core-logging-server';
|
||||
import { RewritePolicy } from '../policy';
|
||||
|
||||
type MetaRewritePolicyConfigProperties = Array<{
|
||||
path: string;
|
||||
value?: string | number | boolean | null;
|
||||
}>;
|
||||
|
||||
export interface MetaRewritePolicyConfig {
|
||||
type: 'meta';
|
||||
|
||||
/**
|
||||
* The 'mode' specifies what action to perform on the specified properties.
|
||||
* - 'update' updates an existing property at the provided 'path'.
|
||||
* - 'remove' removes an existing property at the provided 'path'.
|
||||
*/
|
||||
mode: 'remove' | 'update';
|
||||
|
||||
/**
|
||||
* The properties to modify.
|
||||
*
|
||||
* @remarks
|
||||
* Each provided 'path' is relative to the record's {@link LogMeta}.
|
||||
* For the 'remove' mode, no 'value' is provided.
|
||||
*/
|
||||
properties: MetaRewritePolicyConfigProperties;
|
||||
}
|
||||
|
||||
export const metaRewritePolicyConfigSchema = schema.object({
|
||||
type: schema.literal('meta'),
|
||||
mode: schema.oneOf([schema.literal('update'), schema.literal('remove')], {
|
|
@ -10,7 +10,8 @@ import type { MockedKeys } from '@kbn/utility-types-jest';
|
|||
import { createRewritePolicyMock, resetAllMocks } from './rewrite_appender.test.mocks';
|
||||
import { rewriteAppenderMocks } from './mocks';
|
||||
import { LogLevel, LogRecord, LogMeta, DisposableAppender } from '@kbn/logging';
|
||||
import { RewriteAppender, RewriteAppenderConfig } from './rewrite_appender';
|
||||
import type { RewriteAppenderConfig } from '@kbn/core-logging-server';
|
||||
import { RewriteAppender } from './rewrite_appender';
|
||||
|
||||
// Helper to ensure tuple is typed [A, B] instead of Array<A | B>
|
||||
const toTuple = <A, B>(a: A, b: B): [A, B] => [a, b];
|
|
@ -8,25 +8,8 @@
|
|||
|
||||
import { schema } from '@kbn/config-schema';
|
||||
import { LogRecord, Appender, DisposableAppender } from '@kbn/logging';
|
||||
import {
|
||||
createRewritePolicy,
|
||||
rewritePolicyConfigSchema,
|
||||
RewritePolicy,
|
||||
RewritePolicyConfig,
|
||||
} from './policies';
|
||||
|
||||
export interface RewriteAppenderConfig {
|
||||
type: 'rewrite';
|
||||
/**
|
||||
* The {@link Appender | appender(s)} to pass the log event to after
|
||||
* implementing the specified rewrite policy.
|
||||
*/
|
||||
appenders: string[];
|
||||
/**
|
||||
* The {@link RewritePolicy | policy} to use to manipulate the provided data.
|
||||
*/
|
||||
policy: RewritePolicyConfig;
|
||||
}
|
||||
import type { RewriteAppenderConfig } from '@kbn/core-logging-server';
|
||||
import { createRewritePolicy, rewritePolicyConfigSchema, RewritePolicy } from './policies';
|
||||
|
||||
/**
|
||||
* Appender that can modify the `LogRecord` instances it receives before passing
|
|
@ -9,30 +9,20 @@
|
|||
import { schema } from '@kbn/config-schema';
|
||||
import moment from 'moment-timezone';
|
||||
import { assertNever } from '@kbn/std';
|
||||
import type {
|
||||
TriggeringPolicyConfig,
|
||||
TimeIntervalTriggeringPolicyConfig,
|
||||
} from '@kbn/core-logging-server';
|
||||
import { TriggeringPolicy } from './policy';
|
||||
import { RollingFileContext } from '../rolling_file_context';
|
||||
import { sizeLimitTriggeringPolicyConfigSchema, SizeLimitTriggeringPolicy } from './size_limit';
|
||||
import {
|
||||
sizeLimitTriggeringPolicyConfigSchema,
|
||||
SizeLimitTriggeringPolicyConfig,
|
||||
SizeLimitTriggeringPolicy,
|
||||
} from './size_limit';
|
||||
import {
|
||||
TimeIntervalTriggeringPolicyConfig,
|
||||
TimeIntervalTriggeringPolicy,
|
||||
timeIntervalTriggeringPolicyConfigSchema,
|
||||
} from './time_interval';
|
||||
|
||||
export type { TriggeringPolicy } from './policy';
|
||||
|
||||
/**
|
||||
* Any of the existing policy's configuration
|
||||
*
|
||||
* See {@link SizeLimitTriggeringPolicyConfig} and {@link TimeIntervalTriggeringPolicyConfig}
|
||||
*/
|
||||
export type TriggeringPolicyConfig =
|
||||
| SizeLimitTriggeringPolicyConfig
|
||||
| TimeIntervalTriggeringPolicyConfig;
|
||||
|
||||
const defaultPolicy: TimeIntervalTriggeringPolicyConfig = {
|
||||
type: 'time-interval',
|
||||
interval: moment.duration(24, 'hour'),
|
|
@ -10,5 +10,3 @@ export {
|
|||
SizeLimitTriggeringPolicy,
|
||||
sizeLimitTriggeringPolicyConfigSchema,
|
||||
} from './size_limit_policy';
|
||||
|
||||
export type { SizeLimitTriggeringPolicyConfig } from './size_limit_policy';
|
|
@ -6,20 +6,12 @@
|
|||
* Side Public License, v 1.
|
||||
*/
|
||||
|
||||
import { schema, ByteSizeValue } from '@kbn/config-schema';
|
||||
import { schema } from '@kbn/config-schema';
|
||||
import { LogRecord } from '@kbn/logging';
|
||||
import type { SizeLimitTriggeringPolicyConfig } from '@kbn/core-logging-server';
|
||||
import { RollingFileContext } from '../../rolling_file_context';
|
||||
import { TriggeringPolicy } from '../policy';
|
||||
|
||||
export interface SizeLimitTriggeringPolicyConfig {
|
||||
type: 'size-limit';
|
||||
|
||||
/**
|
||||
* The minimum size the file must have to roll over.
|
||||
*/
|
||||
size: ByteSizeValue;
|
||||
}
|
||||
|
||||
export const sizeLimitTriggeringPolicyConfigSchema = schema.object({
|
||||
type: schema.literal('size-limit'),
|
||||
size: schema.byteSize({ min: '1b', defaultValue: '100mb' }),
|
|
@ -10,5 +10,4 @@ export {
|
|||
TimeIntervalTriggeringPolicy,
|
||||
timeIntervalTriggeringPolicyConfigSchema,
|
||||
} from './time_interval_policy';
|
||||
|
||||
export type { TimeIntervalTriggeringPolicyConfig } from './time_interval_policy';
|
||||
export { getNextRollingTime } from './get_next_rolling_time';
|
|
@ -10,10 +10,8 @@ import { getNextRollingTimeMock } from './time_interval_policy.test.mocks';
|
|||
import moment from 'moment-timezone';
|
||||
import { LogLevel, LogRecord } from '@kbn/logging';
|
||||
import { schema } from '@kbn/config-schema';
|
||||
import {
|
||||
TimeIntervalTriggeringPolicy,
|
||||
TimeIntervalTriggeringPolicyConfig,
|
||||
} from './time_interval_policy';
|
||||
import type { TimeIntervalTriggeringPolicyConfig } from '@kbn/core-logging-server';
|
||||
import { TimeIntervalTriggeringPolicy } from './time_interval_policy';
|
||||
import { RollingFileContext } from '../../rolling_file_context';
|
||||
|
||||
const format = 'YYYY-MM-DD HH:mm:ss';
|
|
@ -6,37 +6,14 @@
|
|||
* Side Public License, v 1.
|
||||
*/
|
||||
|
||||
import { Duration } from 'moment-timezone';
|
||||
import { schema } from '@kbn/config-schema';
|
||||
import { LogRecord } from '@kbn/logging';
|
||||
import type { TimeIntervalTriggeringPolicyConfig } from '@kbn/core-logging-server';
|
||||
import { RollingFileContext } from '../../rolling_file_context';
|
||||
import { TriggeringPolicy } from '../policy';
|
||||
import { getNextRollingTime } from './get_next_rolling_time';
|
||||
import { isValidRolloverInterval } from './utils';
|
||||
|
||||
export interface TimeIntervalTriggeringPolicyConfig {
|
||||
type: 'time-interval';
|
||||
|
||||
/**
|
||||
* How often a rollover should occur.
|
||||
*
|
||||
* @remarks
|
||||
* Due to how modulate rolling works, it is required to have an integer value for the highest time unit
|
||||
* of the duration (you can't overflow to a higher unit).
|
||||
* For example, `15m` and `4h` are valid values , but `90m` is not (as it is `1.5h`).
|
||||
*/
|
||||
interval: Duration;
|
||||
|
||||
/**
|
||||
* Indicates whether the interval should be adjusted to cause the next rollover to occur on the interval boundary.
|
||||
*
|
||||
* For example, if the interval is `4h` and the current hour is 3 am then
|
||||
* the first rollover will occur at 4 am and then next ones will occur at 8 am, noon, 4pm, etc.
|
||||
* The default value is true.
|
||||
*/
|
||||
modulate: boolean;
|
||||
}
|
||||
|
||||
export const timeIntervalTriggeringPolicyConfigSchema = schema.object({
|
||||
type: schema.literal('time-interval'),
|
||||
interval: schema.duration({
|
|
@ -17,7 +17,8 @@ import {
|
|||
import { rollingFileAppenderMocks } from './mocks';
|
||||
import moment from 'moment-timezone';
|
||||
import { LogLevel, LogRecord } from '@kbn/logging';
|
||||
import { RollingFileAppender, RollingFileAppenderConfig } from './rolling_file_appender';
|
||||
import type { RollingFileAppenderConfig } from '@kbn/core-logging-server';
|
||||
import { RollingFileAppender } from './rolling_file_appender';
|
||||
|
||||
const config: RollingFileAppenderConfig = {
|
||||
type: 'rolling-file',
|
|
@ -8,43 +8,14 @@
|
|||
|
||||
import { schema } from '@kbn/config-schema';
|
||||
import { LogRecord, Layout, DisposableAppender } from '@kbn/logging';
|
||||
import { Layouts, LayoutConfigType } from '../../layouts/layouts';
|
||||
import type { RollingFileAppenderConfig } from '@kbn/core-logging-server';
|
||||
import { Layouts } from '../../layouts/layouts';
|
||||
import { BufferAppender } from '../buffer/buffer_appender';
|
||||
import {
|
||||
TriggeringPolicyConfig,
|
||||
createTriggeringPolicy,
|
||||
triggeringPolicyConfigSchema,
|
||||
TriggeringPolicy,
|
||||
} from './policies';
|
||||
import {
|
||||
RollingStrategy,
|
||||
createRollingStrategy,
|
||||
RollingStrategyConfig,
|
||||
rollingStrategyConfigSchema,
|
||||
} from './strategies';
|
||||
import { createTriggeringPolicy, triggeringPolicyConfigSchema, TriggeringPolicy } from './policies';
|
||||
import { RollingStrategy, createRollingStrategy, rollingStrategyConfigSchema } from './strategies';
|
||||
import { RollingFileManager } from './rolling_file_manager';
|
||||
import { RollingFileContext } from './rolling_file_context';
|
||||
|
||||
export interface RollingFileAppenderConfig {
|
||||
type: 'rolling-file';
|
||||
/**
|
||||
* The layout to use when writing log entries
|
||||
*/
|
||||
layout: LayoutConfigType;
|
||||
/**
|
||||
* The absolute path of the file to write to.
|
||||
*/
|
||||
fileName: string;
|
||||
/**
|
||||
* The {@link TriggeringPolicy | policy} to use to determine if a rollover should occur.
|
||||
*/
|
||||
policy: TriggeringPolicyConfig;
|
||||
/**
|
||||
* The {@link RollingStrategy | rollout strategy} to use for rolling.
|
||||
*/
|
||||
strategy: RollingStrategyConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* Appender that formats all the `LogRecord` instances it receives and writes them to the specified file.
|
||||
* @internal
|
|
@ -7,12 +7,9 @@
|
|||
*/
|
||||
|
||||
import { schema } from '@kbn/config-schema';
|
||||
import type { NumericRollingStrategyConfig } from '@kbn/core-logging-server';
|
||||
import { RollingStrategy } from './strategy';
|
||||
import {
|
||||
NumericRollingStrategy,
|
||||
NumericRollingStrategyConfig,
|
||||
numericRollingStrategyConfigSchema,
|
||||
} from './numeric';
|
||||
import { NumericRollingStrategy, numericRollingStrategyConfigSchema } from './numeric';
|
||||
import { RollingFileContext } from '../rolling_file_context';
|
||||
|
||||
export type { RollingStrategy } from './strategy';
|
|
@ -7,5 +7,3 @@
|
|||
*/
|
||||
|
||||
export { NumericRollingStrategy, numericRollingStrategyConfigSchema } from './numeric_strategy';
|
||||
|
||||
export type { NumericRollingStrategyConfig } from './numeric_strategy';
|
|
@ -16,7 +16,8 @@ import {
|
|||
rollPreviousFilesInOrderMock,
|
||||
} from './numeric_strategy.test.mocks';
|
||||
import { rollingFileAppenderMocks } from '../../mocks';
|
||||
import { NumericRollingStrategy, NumericRollingStrategyConfig } from './numeric_strategy';
|
||||
import type { NumericRollingStrategyConfig } from '@kbn/core-logging-server';
|
||||
import { NumericRollingStrategy } from './numeric_strategy';
|
||||
|
||||
const logFileFolder = 'log-file-folder';
|
||||
const logFileBaseName = 'kibana.log';
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
import { basename, dirname } from 'path';
|
||||
import { schema } from '@kbn/config-schema';
|
||||
import type { NumericRollingStrategyConfig } from '@kbn/core-logging-server';
|
||||
import { RollingStrategy } from '../strategy';
|
||||
import { RollingFileContext } from '../../rolling_file_context';
|
||||
import {
|
||||
|
@ -18,39 +19,6 @@ import {
|
|||
rollPreviousFilesInOrder,
|
||||
} from './rolling_tasks';
|
||||
|
||||
export interface NumericRollingStrategyConfig {
|
||||
type: 'numeric';
|
||||
/**
|
||||
* The suffix pattern to apply when renaming a file. The suffix will be applied
|
||||
* after the `appender.fileName` file name, but before the file extension.
|
||||
*
|
||||
* Must include `%i`, as it is the value that will be converted to the file index
|
||||
*
|
||||
* @example
|
||||
* ```yaml
|
||||
* logging:
|
||||
* appenders:
|
||||
* rolling-file:
|
||||
* type: rolling-file
|
||||
* fileName: /var/logs/kibana.log
|
||||
* strategy:
|
||||
* type: default
|
||||
* pattern: "-%i"
|
||||
* max: 5
|
||||
* ```
|
||||
*
|
||||
* will create `/var/logs/kibana-1.log`, `/var/logs/kibana-2.log`, and so on.
|
||||
*
|
||||
* Defaults to `-%i`.
|
||||
*/
|
||||
pattern: string;
|
||||
/**
|
||||
* The maximum number of files to keep. Once this number is reached, oldest
|
||||
* files will be deleted. Defaults to `7`
|
||||
*/
|
||||
max: number;
|
||||
}
|
||||
|
||||
export const numericRollingStrategyConfigSchema = schema.object({
|
||||
type: schema.literal('numeric'),
|
||||
pattern: schema.string({
|
|
@ -7,20 +7,15 @@
|
|||
*/
|
||||
|
||||
export { config } from './logging_config';
|
||||
export type {
|
||||
LoggingConfigType,
|
||||
LoggerContextConfigInput,
|
||||
LoggerConfigType,
|
||||
loggerContextConfigSchema,
|
||||
loggerSchema,
|
||||
} from './logging_config';
|
||||
export type { LoggingConfigType, loggerContextConfigSchema, loggerSchema } from './logging_config';
|
||||
export { LoggingSystem } from './logging_system';
|
||||
export type { ILoggingSystem } from './logging_system';
|
||||
export { LoggingService } from './logging_service';
|
||||
export type {
|
||||
InternalLoggingServicePreboot,
|
||||
InternalLoggingServiceSetup,
|
||||
LoggingServiceSetup,
|
||||
PrebootDeps,
|
||||
} from './logging_service';
|
||||
export { appendersSchema } from './appenders/appenders';
|
||||
export type { AppenderConfigType } from './appenders/appenders';
|
||||
export { LoggerAdapter } from './logger_adapter';
|
||||
export { getNextRollingTime } from './appenders/rolling_file/policies/time_interval';
|
|
@ -17,11 +17,6 @@ const jsonLayoutSchema = object({
|
|||
type: literal('json'),
|
||||
});
|
||||
|
||||
/** @internal */
|
||||
export interface JsonLayoutConfigType {
|
||||
type: 'json';
|
||||
}
|
||||
|
||||
/**
|
||||
* Layout that just converts `LogRecord` into JSON string.
|
||||
* @internal
|
|
@ -9,14 +9,13 @@
|
|||
import { schema } from '@kbn/config-schema';
|
||||
import { Layout } from '@kbn/logging';
|
||||
import { assertNever } from '@kbn/std';
|
||||
import type { LayoutConfigType } from '@kbn/core-logging-server';
|
||||
|
||||
import { JsonLayout, JsonLayoutConfigType } from './json_layout';
|
||||
import { PatternLayout, PatternLayoutConfigType } from './pattern_layout';
|
||||
import { JsonLayout } from './json_layout';
|
||||
import { PatternLayout } from './pattern_layout';
|
||||
|
||||
const { oneOf } = schema;
|
||||
|
||||
export type LayoutConfigType = PatternLayoutConfigType | JsonLayoutConfigType;
|
||||
|
||||
/** @internal */
|
||||
export class Layouts {
|
||||
public static configSchema = oneOf([JsonLayout.configSchema, PatternLayout.configSchema]);
|
|
@ -6,10 +6,21 @@
|
|||
* Side Public License, v 1.
|
||||
*/
|
||||
|
||||
import stripAnsi from 'strip-ansi';
|
||||
import hasAnsi from 'has-ansi';
|
||||
import { LogLevel, LogRecord } from '@kbn/logging';
|
||||
import { stripAnsiSnapshotSerializer } from '../../../test_helpers/strip_ansi_snapshot_serializer';
|
||||
import { PatternLayout, patternSchema } from './pattern_layout';
|
||||
|
||||
const stripAnsiSnapshotSerializer: jest.SnapshotSerializerPlugin = {
|
||||
serialize(value: string) {
|
||||
return stripAnsi(value);
|
||||
},
|
||||
|
||||
test(value: any) {
|
||||
return typeof value === 'string' && hasAnsi(value);
|
||||
},
|
||||
};
|
||||
|
||||
const timestamp = new Date(Date.UTC(2012, 1, 1, 14, 30, 22, 11));
|
||||
const records: LogRecord[] = [
|
||||
{
|
|
@ -45,13 +45,6 @@ const conversions: Conversion[] = [
|
|||
DateConversion,
|
||||
];
|
||||
|
||||
/** @internal */
|
||||
export interface PatternLayoutConfigType {
|
||||
type: 'pattern';
|
||||
highlight?: boolean;
|
||||
pattern?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Layout that formats `LogRecord` using the `pattern` string with optional
|
||||
* color highlighting (eg. to make log messages easier to read in the terminal).
|
|
@ -7,7 +7,8 @@
|
|||
*/
|
||||
|
||||
import { schema, TypeOf } from '@kbn/config-schema';
|
||||
import { AppenderConfigType, Appenders } from './appenders/appenders';
|
||||
import type { AppenderConfigType, LoggerConfigType } from '@kbn/core-logging-server';
|
||||
import { Appenders } from './appenders/appenders';
|
||||
|
||||
// We need this helper for the types to be correct
|
||||
// (otherwise it assumes an array of A|B instead of a tuple [A,B])
|
||||
|
@ -55,9 +56,6 @@ export const loggerSchema = schema.object({
|
|||
level: levelSchema,
|
||||
});
|
||||
|
||||
/** @public */
|
||||
export type LoggerConfigType = TypeOf<typeof loggerSchema>;
|
||||
|
||||
export const config = {
|
||||
path: 'logging',
|
||||
schema: schema.object({
|
||||
|
@ -77,6 +75,7 @@ export const config = {
|
|||
}),
|
||||
};
|
||||
|
||||
/** @internal */
|
||||
export type LoggingConfigType = Pick<TypeOf<typeof config.schema>, 'loggers' | 'root'> & {
|
||||
appenders: Map<string, AppenderConfigType>;
|
||||
};
|
||||
|
@ -98,13 +97,6 @@ export const loggerContextConfigSchema = schema.object({
|
|||
/** @public */
|
||||
export type LoggerContextConfigType = TypeOf<typeof loggerContextConfigSchema>;
|
||||
|
||||
/** @public */
|
||||
export interface LoggerContextConfigInput {
|
||||
// config-schema knows how to handle either Maps or Records
|
||||
appenders?: Record<string, AppenderConfigType> | Map<string, AppenderConfigType>;
|
||||
loggers?: LoggerConfigType[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Describes the config used to fully setup logging subsystem.
|
||||
* @internal
|
|
@ -8,21 +8,33 @@
|
|||
|
||||
import { of, Subject } from 'rxjs';
|
||||
|
||||
import { loggerMock } from '@kbn/logging-mocks';
|
||||
import {
|
||||
LoggingService,
|
||||
InternalLoggingServiceSetup,
|
||||
InternalLoggingServicePreboot,
|
||||
} from './logging_service';
|
||||
import { loggingSystemMock } from './logging_system.mock';
|
||||
import { LoggerContextConfigType } from './logging_config';
|
||||
import type { ILoggingSystem } from './logging_system';
|
||||
|
||||
const createLoggingSystemMock = () => {
|
||||
const mocked: jest.Mocked<ILoggingSystem> = {
|
||||
get: jest.fn().mockImplementation(() => loggerMock.create()),
|
||||
asLoggerFactory: jest.fn().mockImplementation(() => loggerMock.create()),
|
||||
setContextConfig: jest.fn(),
|
||||
upgrade: jest.fn(),
|
||||
stop: jest.fn(),
|
||||
};
|
||||
return mocked;
|
||||
};
|
||||
|
||||
describe('LoggingService', () => {
|
||||
let loggingSystem: ReturnType<typeof loggingSystemMock.create>;
|
||||
let loggingSystem: jest.Mocked<ILoggingSystem>;
|
||||
let service: LoggingService;
|
||||
let preboot: InternalLoggingServicePreboot;
|
||||
|
||||
beforeEach(() => {
|
||||
loggingSystem = loggingSystemMock.create();
|
||||
loggingSystem = createLoggingSystemMock();
|
||||
service = new LoggingService({ logger: loggingSystem.asLoggerFactory() } as any);
|
||||
preboot = service.preboot({ loggingSystem });
|
||||
});
|
|
@ -9,37 +9,10 @@
|
|||
import { Observable, Subscription } from 'rxjs';
|
||||
import { Logger } from '@kbn/logging';
|
||||
import type { CoreContext, CoreService } from '@kbn/core-base-server-internal';
|
||||
import { LoggingConfig, LoggerContextConfigInput } from './logging_config';
|
||||
import type { LoggerContextConfigInput } from '@kbn/core-logging-server';
|
||||
import { LoggingConfig } from './logging_config';
|
||||
import { ILoggingSystem } from './logging_system';
|
||||
|
||||
/**
|
||||
* Provides APIs to plugins for customizing the plugin's logger.
|
||||
* @public
|
||||
*/
|
||||
export interface LoggingServiceSetup {
|
||||
/**
|
||||
* Customizes the logging config for the plugin's context.
|
||||
*
|
||||
* @remarks
|
||||
* Assumes that that the `context` property of the individual `logger` items emitted by `config$`
|
||||
* are relative to the plugin's logging context (defaults to `plugins.<plugin_id>`).
|
||||
*
|
||||
* @example
|
||||
* Customize the configuration for the plugins.data.search context.
|
||||
* ```ts
|
||||
* core.logging.configure(
|
||||
* of({
|
||||
* appenders: new Map(),
|
||||
* loggers: [{ name: 'search', appenders: ['default'] }]
|
||||
* })
|
||||
* )
|
||||
* ```
|
||||
*
|
||||
* @param config$
|
||||
*/
|
||||
configure(config$: Observable<LoggerContextConfigInput>): void;
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
export interface InternalLoggingServicePreboot {
|
||||
configure(contextParts: string[], config$: Observable<LoggerContextConfigInput>): void;
|
|
@ -7,16 +7,15 @@
|
|||
*/
|
||||
|
||||
import { DisposableAppender, LogLevel, Logger, LoggerFactory } from '@kbn/logging';
|
||||
import type { LoggerConfigType, LoggerContextConfigInput } from '@kbn/core-logging-server';
|
||||
import { Appenders } from './appenders/appenders';
|
||||
import { BufferAppender } from './appenders/buffer/buffer_appender';
|
||||
import { BaseLogger } from './logger';
|
||||
import { LoggerAdapter } from './logger_adapter';
|
||||
import {
|
||||
LoggingConfigType,
|
||||
LoggerConfigType,
|
||||
LoggingConfig,
|
||||
LoggerContextConfigType,
|
||||
LoggerContextConfigInput,
|
||||
loggerContextConfigSchema,
|
||||
config as loggingConfig,
|
||||
} from './logging_config';
|
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
"extends": "../../../../tsconfig.bazel.json",
|
||||
"compilerOptions": {
|
||||
"declaration": true,
|
||||
"emitDeclarationOnly": true,
|
||||
"outDir": "target_types",
|
||||
"rootDir": "src",
|
||||
"stripInternal": false,
|
||||
"types": [
|
||||
"jest",
|
||||
"node"
|
||||
]
|
||||
},
|
||||
"include": [
|
||||
"src/**/*"
|
||||
]
|
||||
}
|
101
packages/core/logging/core-logging-server-mocks/BUILD.bazel
Normal file
101
packages/core/logging/core-logging-server-mocks/BUILD.bazel
Normal file
|
@ -0,0 +1,101 @@
|
|||
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-server-mocks"
|
||||
PKG_REQUIRE_NAME = "@kbn/core-logging-server-mocks"
|
||||
|
||||
SOURCE_FILES = glob(
|
||||
[
|
||||
"src/**/*.ts",
|
||||
],
|
||||
exclude = [
|
||||
"**/*.test.*",
|
||||
],
|
||||
)
|
||||
|
||||
SRCS = SOURCE_FILES
|
||||
|
||||
filegroup(
|
||||
name = "srcs",
|
||||
srcs = SRCS,
|
||||
)
|
||||
|
||||
NPM_MODULE_EXTRA_FILES = [
|
||||
"package.json",
|
||||
]
|
||||
|
||||
RUNTIME_DEPS = [
|
||||
"//packages/kbn-logging-mocks"
|
||||
]
|
||||
|
||||
TYPES_DEPS = [
|
||||
"@npm//@types/node",
|
||||
"@npm//@types/jest",
|
||||
"//packages/kbn-utility-types:npm_module_types",
|
||||
"//packages/kbn-logging:npm_module_types",
|
||||
"//packages/kbn-logging-mocks:npm_module_types",
|
||||
"//packages/core/logging/core-logging-server:npm_module_types",
|
||||
"//packages/core/logging/core-logging-server-internal:npm_module_types",
|
||||
]
|
||||
|
||||
jsts_transpiler(
|
||||
name = "target_node",
|
||||
srcs = SRCS,
|
||||
build_pkg_name = package_name(),
|
||||
)
|
||||
|
||||
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",
|
||||
root_dir = "src",
|
||||
tsconfig = ":tsconfig",
|
||||
)
|
||||
|
||||
js_library(
|
||||
name = PKG_DIRNAME,
|
||||
srcs = NPM_MODULE_EXTRA_FILES,
|
||||
deps = RUNTIME_DEPS + [":target_node"],
|
||||
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_types(
|
||||
name = "npm_module_types",
|
||||
srcs = SRCS,
|
||||
deps = [":tsc_types"],
|
||||
package_name = PKG_REQUIRE_NAME,
|
||||
tsconfig = ":tsconfig",
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "build_types",
|
||||
srcs = [":npm_module_types"],
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
|
@ -0,0 +1,3 @@
|
|||
# @kbn/core-logging-server-mocks
|
||||
|
||||
This package contains the mocks for Core's server-side logging service.
|
|
@ -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/jest_node',
|
||||
rootDir: '../../../..',
|
||||
roots: ['<rootDir>/packages/core/logging/core-logging-server-mocks'],
|
||||
};
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"name": "@kbn/core-logging-server-mocks",
|
||||
"private": true,
|
||||
"version": "1.0.0",
|
||||
"main": "./target_node/index.js",
|
||||
"license": "SSPL-1.0 OR Elastic License 2.0"
|
||||
}
|
10
packages/core/logging/core-logging-server-mocks/src/index.ts
Normal file
10
packages/core/logging/core-logging-server-mocks/src/index.ts
Normal file
|
@ -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 { loggingSystemMock } from './logging_system.mock';
|
||||
export { loggingServiceMock } from './logging_service.mock';
|
|
@ -7,13 +7,12 @@
|
|||
*/
|
||||
|
||||
import type { PublicMethodsOf } from '@kbn/utility-types';
|
||||
|
||||
import {
|
||||
import type { LoggingServiceSetup } from '@kbn/core-logging-server';
|
||||
import type {
|
||||
LoggingService,
|
||||
LoggingServiceSetup,
|
||||
InternalLoggingServiceSetup,
|
||||
InternalLoggingServicePreboot,
|
||||
} from './logging_service';
|
||||
} from '@kbn/core-logging-server-internal';
|
||||
|
||||
const createInternalPrebootMock = (): jest.Mocked<InternalLoggingServicePreboot> => ({
|
||||
configure: jest.fn(),
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue