-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Feat: created logEntry class and test cases Chore: relocated createLogs to abstracted func Chore: renamed schema idx to prefix with '__'
- Loading branch information
1 parent
bc93fcf
commit 89dadf5
Showing
12 changed files
with
212 additions
and
98 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import LogEntry, { LogType, LogLevel } from './log-entry'; | ||
|
||
describe('LogEntry', () => { | ||
test('create a system debug log entry', () => { | ||
const blockHeight = 100; | ||
const logEntry = LogEntry.systemDebug('Debug message', blockHeight); | ||
expect(logEntry.message).toBe('Debug message'); | ||
expect(logEntry.level).toBe(LogLevel.DEBUG); | ||
expect(logEntry.type).toBe(LogType.SYSTEM); | ||
expect(logEntry.timestamp).toBeInstanceOf(Date); | ||
expect(logEntry.blockHeight).toBe(blockHeight); | ||
}); | ||
|
||
test('create a system info log entry', () => { | ||
const blockHeight = 100; | ||
const logEntry = LogEntry.systemInfo('Info message', blockHeight); | ||
expect(logEntry.message).toBe('Info message'); | ||
expect(logEntry.level).toBe(LogLevel.INFO); | ||
expect(logEntry.type).toBe(LogType.SYSTEM); | ||
expect(logEntry.timestamp).toBeInstanceOf(Date); | ||
expect(logEntry.blockHeight).toBe(blockHeight); | ||
}); | ||
|
||
test('create a system warn log entry', () => { | ||
const blockHeight = 100; | ||
const logEntry = LogEntry.systemWarn('Warn message', blockHeight); | ||
expect(logEntry.message).toBe('Warn message'); | ||
expect(logEntry.level).toBe(LogLevel.WARN); | ||
expect(logEntry.type).toBe(LogType.SYSTEM); | ||
expect(logEntry.timestamp).toBeInstanceOf(Date); | ||
expect(logEntry.blockHeight).toBe(blockHeight); | ||
}); | ||
|
||
test('create a system error log entry', () => { | ||
const blockHeight = 100; | ||
const logEntry = LogEntry.systemError('Error message', blockHeight); | ||
expect(logEntry.message).toBe('Error message'); | ||
expect(logEntry.level).toBe(LogLevel.ERROR); | ||
expect(logEntry.type).toBe(LogType.SYSTEM); | ||
expect(logEntry.timestamp).toBeInstanceOf(Date); | ||
expect(logEntry.blockHeight).toBe(blockHeight); | ||
}); | ||
|
||
test('create a user debug log entry', () => { | ||
const blockHeight = 100; | ||
const logEntry = LogEntry.userDebug('Debug message', blockHeight); | ||
expect(logEntry.message).toBe('Debug message'); | ||
expect(logEntry.level).toBe(LogLevel.DEBUG); | ||
expect(logEntry.type).toBe(LogType.USER); | ||
expect(logEntry.timestamp).toBeInstanceOf(Date); | ||
expect(logEntry.blockHeight).toBe(blockHeight); | ||
}); | ||
|
||
test('create a user info log entry', () => { | ||
const blockHeight = 100; | ||
const logEntry = LogEntry.userInfo('User info message', blockHeight); | ||
expect(logEntry.message).toBe('User info message'); | ||
expect(logEntry.level).toBe(LogLevel.INFO); | ||
expect(logEntry.type).toBe(LogType.USER); | ||
expect(logEntry.timestamp).toBeInstanceOf(Date); | ||
expect(logEntry.blockHeight).toBe(blockHeight); | ||
}); | ||
|
||
test('create a user warn log entry', () => { | ||
const blockHeight = 100; | ||
const logEntry = LogEntry.userWarn('User warn message', blockHeight); | ||
expect(logEntry.message).toBe('User warn message'); | ||
expect(logEntry.level).toBe(LogLevel.WARN); | ||
expect(logEntry.type).toBe(LogType.USER); | ||
expect(logEntry.timestamp).toBeInstanceOf(Date); | ||
expect(logEntry.blockHeight).toBe(blockHeight); | ||
}); | ||
|
||
test('create a user error log entry', () => { | ||
const blockHeight = 100; | ||
const logEntry = LogEntry.userError('User error message', blockHeight); | ||
expect(logEntry.message).toBe('User error message'); | ||
expect(logEntry.level).toBe(LogLevel.ERROR); | ||
expect(logEntry.type).toBe(LogType.USER); | ||
expect(logEntry.timestamp).toBeInstanceOf(Date); | ||
expect(logEntry.blockHeight).toBe(blockHeight); | ||
}); | ||
|
||
test('create a system info log entry without blockheight', () => { | ||
const logEntry = LogEntry.systemInfo('Info message'); | ||
expect(logEntry.message).toBe('Info message'); | ||
expect(logEntry.level).toBe(LogLevel.INFO); | ||
expect(logEntry.type).toBe(LogType.SYSTEM); | ||
expect(logEntry.timestamp).toBeInstanceOf(Date); | ||
expect(logEntry.blockHeight).toBeUndefined(); | ||
}); | ||
}); |
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,60 @@ | ||
export enum LogLevel { | ||
DEBUG = 2, | ||
INFO = 5, | ||
WARN = 6, | ||
ERROR = 8, | ||
} | ||
|
||
export enum LogType { | ||
SYSTEM = 'system', | ||
USER = 'user', | ||
} | ||
|
||
export default class LogEntry { | ||
public readonly timestamp: Date; | ||
|
||
constructor ( | ||
public readonly message: string, | ||
public readonly level: LogLevel, | ||
public readonly type: LogType, | ||
public readonly blockHeight?: number | ||
) { | ||
this.timestamp = new Date(); | ||
} | ||
|
||
static createLog (message: string, level: LogLevel, type: LogType, blockHeight?: number): LogEntry { | ||
return new LogEntry(message, level, type, blockHeight); | ||
} | ||
|
||
static systemDebug (message: string, blockHeight?: number): LogEntry { | ||
return LogEntry.createLog(message, LogLevel.DEBUG, LogType.SYSTEM, blockHeight); | ||
} | ||
|
||
static systemInfo (message: string, blockHeight?: number): LogEntry { | ||
return LogEntry.createLog(message, LogLevel.INFO, LogType.SYSTEM, blockHeight); | ||
} | ||
|
||
static systemWarn (message: string, blockHeight?: number): LogEntry { | ||
return LogEntry.createLog(message, LogLevel.WARN, LogType.SYSTEM, blockHeight); | ||
} | ||
|
||
static systemError (message: string, blockHeight?: number): LogEntry { | ||
return LogEntry.createLog(message, LogLevel.ERROR, LogType.SYSTEM, blockHeight); | ||
} | ||
|
||
static userDebug (message: string, blockHeight?: number): LogEntry { | ||
return LogEntry.createLog(message, LogLevel.DEBUG, LogType.USER, blockHeight); | ||
} | ||
|
||
static userInfo (message: string, blockHeight?: number): LogEntry { | ||
return LogEntry.createLog(message, LogLevel.INFO, LogType.USER, blockHeight); | ||
} | ||
|
||
static userWarn (message: string, blockHeight?: number): LogEntry { | ||
return LogEntry.createLog(message, LogLevel.WARN, LogType.USER, blockHeight); | ||
} | ||
|
||
static userError (message: string, blockHeight?: number): LogEntry { | ||
return LogEntry.createLog(message, LogLevel.ERROR, LogType.USER, blockHeight); | ||
} | ||
} |
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
Oops, something went wrong.