Use tdslint to lint typings file, add index to export schema

The project dependencies now rely on a tdslint to lint the typings file
as well as testing against the test file. These files are found under
types.

A index.js file is provided to expose the schema itself.
Signed-off-by: default avatarSnorre Magnus Davøen <snorre.davoen@nsd.uib.no>
parent da0a736f
const schema = require('./log-schema/log-schema.json');
export default schema;
\ No newline at end of file
export interface LogSchema {
/**
* The version of the log-schema. Used to separate versions into different Elasticsearch indices.
*/
schemaVersion: "v3";
/**
* The time of the event. Format: RFC 3339. (E.g. 1985-04-12T23:20:50.52Z)
*/
"@timestamp": string;
/**
* Log-level (DEBUG|INFO|WARN|ERROR).
*/
levelName: ("DEBUG" | "INFO" | "WARN" | "ERROR");
/**
* Same as the message parameter in log libraries. Should contain a message describing log event.
*/
message: string;
/**
* The process to which the log event pertains.
*/
process?: string;
/**
* The thread to which the log event pertains.
*/
thread?: string;
/**
* The application file to which the log event pertains.
*/
file?: string;
/**
* The line number to which the log event pertains.
*/
line?: number;
/**
* Identification of user to which log event pertains. Can be used to view log events for specific users.
*/
userId?: string;
/**
* Name of logger generating the log event.
*/
loggerName?: string;
/**
* Name of the service. E.g. user-service.
*/
serviceName: string;
/**
* Version of the service. E.g. v2.0.2.
*/
serviceVersion: string;
serviceStack?: string;
/**
* The id of a client/user request. Used to track a single request across services.
*/
xRequestId?: string;
/**
* String tags to help categorize and/or filter log events
*/
tags?: string[];
/**
* The current hostname for the service instance.
*/
host?: string;
/**
* The current port number for the service instance.
*/
port?: number;
/**
* A regular string or stringified JSON object containing data about log event.
*/
data?: string;
/**
* The URL from which the log event was initiated.
*/
url?: string;
/**
* The number of milliseconds spent on request/process.
*/
responseTime?: number;
/**
* HTTP status code if applicable.
*/
statusCode?: number;
/**
* HTTP method if applicable.
*/
method?: string;
error?: {
/**
* A string representation of error type, e.g. NO_SUCH_VARIABLE_ERROR.
*/
type?: string;
/**
* Error code uniquely identifiying error. E.g. 4324.
*/
code: string;
/**
* Name of service where error originated if the error originated outside this service.
*/
serviceName?: string;
/**
* Stack trace for the error. Should be santizied of sensitive information if possible.
*/
stack?: string;
/**
* Any data that may be related to error in string format.
*/
data?: string;
/**
* Regular string or stringified json object of original error object
*/
originalErrorObject?: string;
};
request?: {
/**
* Request headers like Accept, If-Modified-Since, etc. Avoid logging sensitive headers!
*/
headers?: {
[k: string]: string;
};
/**
* Query parameters contained within URL. E.g. (?myvalue=foo)
*/
query?: {
[k: string]: string;
};
/**
* Path parameters contained whithin URL. E.g. /resource/<pathparam>
*/
path?: {
[k: string]: string;
};
/**
* The request payload/body if applicable (POST form, json payload, etc).
*/
payload?: string;
};
response?: {
/**
* Response headers like eTag, Content-Length, etc. Avoid logging sensitive headers!
*/
headers?: {
[k: string]: string;
};
/**
* A string representation of the response body. Do not log large bodies!
*/
body?: string;
};
}
......@@ -2,12 +2,16 @@
"name": "log-schema-node",
"version": "1.0.0",
"main": "./log-schema/log-schema.json",
"types": "./log-schema.d.ts",
"types": "types",
"scripts": {
"dtslint": "dtslint types"
},
"repository": "git@gitlab.nsd.uib.no:nsd-commons/log-schema-node.git",
"author": "Snorre Magnus Davøen <snorre.davoen@nsd.uib.no>",
"license": "See LICENSE",
"devDependencies": {
"jayschema": "^0.3.1",
"json-schema-to-typescript": "^4.2.0"
"json-schema-to-typescript": "^4.2.0",
"dtslint": "Microsoft/dtslint#production"
}
}
export interface LogSchema {
/**
* The version of the log-schema. Used to separate versions into different Elasticsearch indices.
*/
schemaVersion: "v3";
/**
* The time of the event. Format: RFC 3339. (E.g. 1985-04-12T23:20:50.52Z)
*/
"@timestamp": string;
/**
* Log-level (DEBUG|INFO|WARN|ERROR).
*/
levelName: ("DEBUG" | "INFO" | "WARN" | "ERROR");
/**
* Same as the message parameter in log libraries. Should contain a message describing log event.
*/
message: string;
/**
* The process to which the log event pertains.
*/
process?: string;
/**
* The thread to which the log event pertains.
*/
thread?: string;
/**
* The application file to which the log event pertains.
*/
file?: string;
/**
* The line number to which the log event pertains.
*/
line?: number;
/**
* Identification of user to which log event pertains. Can be used to view log events for specific users.
*/
userId?: string;
/**
* Name of logger generating the log event.
*/
loggerName?: string;
/**
* Name of the service. E.g. user-service.
*/
serviceName: string;
/**
* Version of the service. E.g. v2.0.2.
*/
serviceVersion: string;
serviceStack?: string;
/**
* The id of a client/user request. Used to track a single request across services.
*/
xRequestId?: string;
/**
* String tags to help categorize and/or filter log events
*/
tags?: string[];
/**
* The current hostname for the service instance.
*/
host?: string;
/**
* The current port number for the service instance.
*/
port?: number;
/**
* A regular string or stringified JSON object containing data about log event.
*/
data?: string;
/**
* The URL from which the log event was initiated.
*/
url?: string;
/**
* The number of milliseconds spent on request/process.
*/
responseTime?: number;
/**
* HTTP status code if applicable.
*/
statusCode?: number;
/**
* HTTP method if applicable.
*/
method?: string;
error?: {
/**
* A string representation of error type, e.g. NO_SUCH_VARIABLE_ERROR.
*/
type?: string;
/**
* Error code uniquely identifiying error. E.g. 4324.
*/
code: string;
/**
* Name of service where error originated if the error originated outside this service.
*/
serviceName?: string;
/**
* Stack trace for the error. Should be santizied of sensitive information if possible.
*/
stack?: string;
/**
* Any data that may be related to error in string format.
*/
data?: string;
/**
* Regular string or stringified json object of original error object
*/
originalErrorObject?: string;
};
request?: {
/**
* Request headers like Accept, If-Modified-Since, etc. Avoid logging sensitive headers!
*/
headers?: {
[k: string]: string;
};
/**
* Query parameters contained within URL. E.g. (?myvalue=foo)
*/
query?: {
[k: string]: string | string[];
};
/**
* Path parameters contained whithin URL. E.g. /resource/<pathparam>
*/
path?: {
[k: string]: string;
};
/**
* The request payload/body if applicable (POST form, json payload, etc).
*/
payload?: string;
};
response?: {
/**
* Response headers like eTag, Content-Length, etc. Avoid logging sensitive headers!
*/
headers?: {
[k: string]: string;
};
/**
* A string representation of the response body. Do not log large bodies!
*/
body?: string;
};
}
declare module "log-schema.json" {
const value: LogSchema;
export default value;
}
\ No newline at end of file
import { LogSchema } from "log-schema-node";
import * as schema from "../log-schema/log-schema.json";
const minimalEvent: LogSchema = {
schemaVersion: "v3",
"@timestamp": "1985-04-12T23:20:50.52Z",
levelName: "INFO",
message: "Ørliten melding",
serviceName: "some-service",
serviceVersion: "v1.0.0"
};
const fullEvent: LogSchema = {
schemaVersion: "v3",
"@timestamp": "1985-04-12T23:20:50.52Z",
levelName: "INFO",
message: "Ørliten melding",
userId: "some-user-id",
process: "main process id",
thread: "main thread id",
file: "main.java",
line: 42,
loggerName: "some-logger",
serviceName: "some-service",
serviceVersion: "v1.0.0",
serviceStack: "raird-stage-1",
host: "somehost",
port: 2100,
tags: [
"performance",
],
url: "/v0/hello",
responseTime: 120,
statusCode: 200,
method: "GET",
xRequestId: "cd88dba8-c8e1-4b2e-8a19-bc6220e0be65",
request: {
headers: {
"User-Agent": "curl/7.47.0",
Accept: "*/*"
},
path: {
param1: "param1-value",
param2: "param2-value"
},
query: {
query1: "query1-value",
query2: ["query2-value1", "query2-value2"]
},
payload: "{\"command\": \"tabulate\"}"
},
response: {
headers: {
"Content-Type": "application/octet-stream",
"X-Request-ID": "cd88dba8-c8e1-4b2e-8a19-bc6220e0be65",
"Content-Disposition": "attachment; filename=\"hello.bin\""
},
body: "{\"message\": \"Hello world!\"}"
},
error: {
type: "some-error",
code: "some-error-123",
serviceName: "some-external-service",
stack: "stacktrace1\nstacktrace2\nstacktrace3",
data: "more details...",
originalErrorObject: "stringobject"
},
data: "some-extra-string-data"
};
{
"compilerOptions": {
"module": "commonjs",
"lib": ["es6"],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
// If the library is an external module (uses `export`), this allows your test file to import "mylib" instead of "./index".
// If the library is global (cannot be imported via `import` or `require`), leave this out.
"baseUrl": ".",
"paths": { "log-schema-node": ["."] }
}
}
\ No newline at end of file
{
"extends": "dtslint/dtslint.json",
"rules": {
"semicolon": false,
"indent": [true, "tabs"]
}
}
\ No newline at end of file
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment