1
0
Fork 0

feat(config): stream type for bunyan config

This commit is contained in:
ssube 2019-06-15 19:35:30 -05:00
parent deee5c0cbd
commit 24f91aa1b4
3 changed files with 30 additions and 0 deletions

5
docs/example-config.yml Normal file
View File

@ -0,0 +1,5 @@
data:
logger:
level: debug
name: salty-dog
stream: !stream stderr

View File

@ -7,6 +7,7 @@ import { promisify } from 'util';
import { envType } from 'src/config/type/Env';
import { includeSchema, includeType } from 'src/config/type/Include';
import { regexpType } from 'src/config/type/Regexp';
import { streamType } from 'src/config/type/Stream';
import { NotFoundError } from 'src/error/NotFoundError';
export const CONFIG_ENV = 'SALTY_HOME';
@ -14,6 +15,7 @@ export const CONFIG_SCHEMA = Schema.create([DEFAULT_SAFE_SCHEMA], [
envType,
includeType,
regexpType,
streamType,
]);
includeSchema.schema = CONFIG_SCHEMA;

23
src/config/type/Stream.ts Normal file
View File

@ -0,0 +1,23 @@
import { Type as YamlType } from 'js-yaml';
import { NotFoundError } from 'src/error/NotFoundError';
const ALLOWED_STREAMS = new Set([
'stdout',
'stderr',
]);
export const streamType = new YamlType('!stream', {
kind: 'scalar',
resolve(name: string) {
if (ALLOWED_STREAMS.has(name) && Reflect.has(process, name)) {
return true;
} else {
throw new NotFoundError(`process stream not found: ${name}`);
}
},
construct(name: string) {
return Reflect.get(process, name);
},
});