generated from obsidianmd/obsidian-sample-plugin
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
140 additions
and
46 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,7 @@ | ||
export interface ILogger { | ||
logError(msg: string): void; | ||
|
||
logWarning(msg: string): void; | ||
|
||
logMessage(msg: string): void; | ||
} |
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,32 @@ | ||
import {ErrorLevel} from "./errorLevel"; | ||
import {NoteTweetError} from "./noteTweetError"; | ||
import {NoteTweetLogger} from "./noteTweetLogger"; | ||
|
||
export class ConsoleErrorLogger extends NoteTweetLogger { | ||
public ErrorLog: NoteTweetError[] = []; | ||
|
||
public logError(errorMsg: string) { | ||
const error = this.getNoteTweetError(errorMsg, ErrorLevel.Error); | ||
this.addMessageToErrorLog(error); | ||
|
||
console.error(this.formatOutputString(error)); | ||
} | ||
|
||
public logWarning(warningMsg: string) { | ||
const warning = this.getNoteTweetError(warningMsg, ErrorLevel.Warning); | ||
this.addMessageToErrorLog(warning); | ||
|
||
console.warn(this.formatOutputString(warning)); | ||
} | ||
|
||
public logMessage(logMsg: string) { | ||
const log = this.getNoteTweetError(logMsg, ErrorLevel.Log); | ||
this.addMessageToErrorLog(log); | ||
|
||
console.log(this.formatOutputString(log)); | ||
} | ||
|
||
private addMessageToErrorLog(error: NoteTweetError): void { | ||
this.ErrorLog.push(error); | ||
} | ||
} |
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 @@ | ||
export enum ErrorLevel { Error = "ERROR", Warning = "WARNING", Log = "LOG"} |
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,20 @@ | ||
import {NoteTweetLogger} from "./noteTweetLogger"; | ||
import {TweetErrorModal} from "../Modals/TweetErrorModal"; | ||
import NoteTweet from "../main"; | ||
import {Notice} from "obsidian"; | ||
|
||
export class GuiLogger extends NoteTweetLogger { | ||
constructor(private plugin: NoteTweet) { | ||
super(); | ||
} | ||
|
||
logError(msg: string): void { | ||
new TweetErrorModal(this.plugin.app, msg).open(); | ||
} | ||
|
||
logWarning(msg: string): void { | ||
new Notice(msg); | ||
} | ||
|
||
logMessage(msg: string): void {} | ||
} |
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,25 @@ | ||
import {ILogger} from "./ILogger"; | ||
|
||
class LogManager { | ||
public static loggers: ILogger[] = []; | ||
|
||
public register(logger: ILogger): LogManager { | ||
LogManager.loggers.push(logger); | ||
|
||
return this; | ||
} | ||
|
||
logError(message: string) { | ||
LogManager.loggers.forEach(logger => logger.logError(message)); | ||
} | ||
|
||
logWarning(message: string) { | ||
LogManager.loggers.forEach(logger => logger.logError(message)); | ||
} | ||
|
||
logMessage(message: string) { | ||
LogManager.loggers.forEach(logger => logger.logMessage(message)); | ||
} | ||
} | ||
|
||
export const log = new LogManager(); |
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,7 @@ | ||
import {ErrorLevel} from "./errorLevel"; | ||
|
||
export interface NoteTweetError { | ||
message: string, | ||
level: ErrorLevel, | ||
time: number | ||
} |
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,19 @@ | ||
import {ILogger} from "./ILogger"; | ||
import {NoteTweetError} from "./noteTweetError"; | ||
import {ErrorLevel} from "./errorLevel"; | ||
|
||
export abstract class NoteTweetLogger implements ILogger { | ||
abstract logError(msg: string): void; | ||
|
||
abstract logMessage(msg: string): void; | ||
|
||
abstract logWarning(msg: string): void; | ||
|
||
protected formatOutputString(error: NoteTweetError): string { | ||
return `NoteTweet: (${error.level}) ${error.message}`; | ||
} | ||
|
||
protected getNoteTweetError(message: string, level: ErrorLevel): NoteTweetError { | ||
return {message, level, time: Date.now()}; | ||
} | ||
} |
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
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"0.3.3": "0.9.12", | ||
"0.3.4": "0.12.0", | ||
"0.4.0": "0.12.3" | ||
"0.4.1": "0.12.3" | ||
} |