Skip to content

Commit cdf17ba

Browse files
authored
Merge pull request #178 from SAP/fix-types
Improve TypeScript compatibility
2 parents 8534a6d + 69e9d43 commit cdf17ba

File tree

14 files changed

+166
-142
lines changed

14 files changed

+166
-142
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cf-nodejs-logging-support",
3-
"version": "7.0.0-beta.5",
3+
"version": "7.0.0-beta.6",
44
"description": "Logging tool for Cloud Foundry",
55
"keywords": [
66
"logging",

src/index.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1-
import RootLogger from "./lib/logger/rootLogger"
1+
import RootLogger from "./lib/logger/rootLogger";
22

33
const rootLogger = RootLogger.getInstance();
44

5-
export = rootLogger
5+
module.exports = rootLogger; // assign default export
6+
exports = module.exports; // re-assign exports
7+
8+
export default rootLogger;
9+
export * from "./lib/config/interfaces";
10+
export * from "./lib/logger/level";

src/lib/config/config.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ export default class Config {
2323

2424
private config: ConfigObject = {
2525
"fields": [],
26-
"customFieldsFormat": CustomFieldsFormat.default,
26+
"customFieldsFormat": CustomFieldsFormat.Default,
2727
"reqLoggingLevel": "info",
2828
"outputStartupMsg": false,
29-
"framework": Framework.express
29+
"framework": Framework.Express
3030
}
3131

3232
private constructor() {
@@ -56,11 +56,11 @@ export default class Config {
5656
}
5757

5858
if (boundServices["application-logs"] && boundServices["cloud-logging"]) {
59-
Config.instance.setCustomFieldsFormat(CustomFieldsFormat.all);
59+
Config.instance.setCustomFieldsFormat(CustomFieldsFormat.All);
6060
} else if (boundServices["application-logs"]) {
61-
Config.instance.setCustomFieldsFormat(CustomFieldsFormat.applicationLogging);
61+
Config.instance.setCustomFieldsFormat(CustomFieldsFormat.ApplicationLogging);
6262
} else {
63-
Config.instance.setCustomFieldsFormat(CustomFieldsFormat.cloudLogging);
63+
Config.instance.setCustomFieldsFormat(CustomFieldsFormat.CloudLogging);
6464
}
6565

6666
Config.instance.addConfig(configFiles);
@@ -181,11 +181,11 @@ export default class Config {
181181
field._meta.isCache = true;
182182
}
183183

184-
if (field.output?.includes(Output.msgLog)) {
184+
if (field.output?.includes(Output.MsgLog)) {
185185
this.addToList(this.msgFields, field);
186186
}
187187

188-
if (field.output?.includes(Output.reqLog)) {
188+
if (field.output?.includes(Output.ReqLog)) {
189189
this.addToList(this.reqFields, field);
190190
}
191191

@@ -196,10 +196,10 @@ export default class Config {
196196
}
197197

198198
if (field._meta.isCache == false) {
199-
if (field.output?.includes(Output.msgLog)) {
199+
if (field.output?.includes(Output.MsgLog)) {
200200
this.addToList(this.noCacheMsgFields, field);
201201
}
202-
if (field.output?.includes(Output.reqLog)) {
202+
if (field.output?.includes(Output.ReqLog)) {
203203
this.addToList(this.noCacheReqFields, field);
204204
}
205205
}
@@ -309,9 +309,9 @@ export default class Config {
309309
for (let i in sources) {
310310
let source = sources[i]
311311
switch (source.type) {
312-
case SourceType.static:
312+
case SourceType.Static:
313313
return true;
314-
case SourceType.env:
314+
case SourceType.Env:
315315
// if this is the last source it does not matter, if the env var exists
316316
if (i == (sources.length - 1).toString()) return true
317317

src/lib/config/interfaces.ts

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -40,52 +40,52 @@ export interface ConfigFieldMeta {
4040
}
4141

4242
export enum Framework {
43-
express = "express",
44-
restify = "restify",
45-
connect = "connect",
46-
nodejsHttp = "plainhttp"
43+
Express = "express",
44+
Restify = "restify",
45+
Connect = "connect",
46+
NodeJsHttp = "plainhttp"
4747
}
4848

4949
export enum Output {
50-
msgLog = "msg-log",
51-
reqLog = "req-log"
50+
MsgLog = "msg-log",
51+
ReqLog = "req-log"
5252
}
5353

5454
export enum CustomFieldsFormat {
55-
applicationLogging = "application-logging",
56-
cloudLogging = "cloud-logging",
57-
all = "all",
58-
disabled = "disabled",
59-
default = "default"
55+
ApplicationLogging = "application-logging",
56+
CloudLogging = "cloud-logging",
57+
All = "all",
58+
Disabled = "disabled",
59+
Default = "default"
6060
}
6161

6262
export enum SourceType {
63-
static = "static",
64-
env = "env",
65-
configField = "config-field",
66-
reqHeader = "req-header",
67-
resHeader = "res-header",
68-
reqObject = "req-object",
69-
resObject = "res-object",
70-
detail = "detail",
71-
uuid = "uuid"
63+
Static = "static",
64+
Env = "env",
65+
ConfigField = "config-field",
66+
ReqHeader = "req-header",
67+
ResHeader = "res-header",
68+
ReqObject = "req-object",
69+
ResObject = "res-object",
70+
Detail = "detail",
71+
UUID = "uuid"
7272
}
7373

7474
export enum DetailName {
75-
requestReceivedAt = "requestReceivedAt",
76-
responseSentAt = "responseSentAt",
77-
responseTimeMs = "responseTimeMs",
78-
writtenAt = "writtenAt",
79-
writtenTs = "writtenTs",
80-
message = "message",
81-
stacktrace = "stacktrace",
82-
level = "level"
75+
RequestReceivedAt = "requestReceivedAt",
76+
ResponseSentAt = "responseSentAt",
77+
ResponseTimeMs = "responseTimeMs",
78+
WrittenAt = "writtenAt",
79+
WrittenTs = "writtenTs",
80+
Message = "message",
81+
Stacktrace = "stacktrace",
82+
Level = "level"
8383
}
8484

8585

8686
export enum Conversion {
87-
toString = "toString",
88-
parseInt = "parseInt",
89-
parseFloat = "parseFloat",
90-
parseBoolean = "parseBoolean"
87+
ToString = "toString",
88+
ParseInt = "parseInt",
89+
ParseFloat = "parseFloat",
90+
ParseBoolean = "parseBoolean"
9191
}

src/lib/helper/levelUtils.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
import Level from '../logger/level';
1+
import { Level } from '../logger/level';
22

33
export default class LevelUtils {
44

5-
private static readonly defaultLevel: Level = Level.INFO
5+
private static readonly defaultLevel: Level = Level.Info
66

77
static getLevel(name: string): Level {
8-
const level: Level = Level[name.toUpperCase() as keyof typeof Level]
8+
const key = name.charAt(0).toUpperCase() + name.slice(1).toLowerCase();
9+
const level: Level = Level[key as keyof typeof Level]
910
if (level === undefined) {
1011
return LevelUtils.defaultLevel;
1112
}
@@ -17,7 +18,7 @@ export default class LevelUtils {
1718
}
1819

1920
static isLevelEnabled(threshold: Level, level: Level) {
20-
if (level <= Level.OFF) return false;
21+
if (level <= Level.Off) return false;
2122
return level <= threshold
2223
}
2324
}

src/lib/logger/cache.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ export default class Cache {
2626

2727
getCacheMsgRecord(cacheFields: ConfigField[]): any {
2828
if (this.shouldUpdateMsg) {
29-
this.updateCache(Output.msgLog, cacheFields);
29+
this.updateCache(Output.MsgLog, cacheFields);
3030
this.shouldUpdateMsg = false;
3131
}
3232
return this.cacheMsgRecord;
3333
}
3434

3535
getCacheReqRecord(cacheFields: ConfigField[], req: any, res: any): any {
3636
if (this.shouldUpdateReq) {
37-
this.updateCache(Output.reqLog, cacheFields, req, res);
37+
this.updateCache(Output.ReqLog, cacheFields, req, res);
3838
this.shouldUpdateReq = false;
3939
}
4040
return this.cacheReqRecord;
@@ -48,7 +48,7 @@ export default class Cache {
4848
private updateCache(output: Output, cacheFields: ConfigField[], req?: any, res?: any) {
4949
let cache: any = {};
5050

51-
if (output == Output.msgLog) {
51+
if (output == Output.MsgLog) {
5252
this.cacheMsgRecord = {};
5353
cache = this.cacheMsgRecord;
5454
} else {

src/lib/logger/level.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
enum Level {
2-
INHERIT = -2,
3-
OFF = -1,
4-
ERROR = 0,
5-
WARN = 1,
6-
INFO = 2,
7-
VERBOSE = 3,
8-
DEBUG = 4,
9-
SILLY = 5
1+
export enum Level {
2+
Inherit = -2,
3+
Off = -1,
4+
Error = 0,
5+
Warn = 1,
6+
Info = 2,
7+
Verbose = 3,
8+
Debug = 4,
9+
Silly = 5
1010
}
11-
12-
export default Level

0 commit comments

Comments
 (0)