-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
c8ad767
commit e63b812
Showing
17 changed files
with
336 additions
and
24 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,11 +2,11 @@ | |
* ? ABOUT | ||
* @author : Cody Spratford | ||
* @email : [email protected] | ||
* @repo : | ||
* @repo : https://github.com/koreanpanda345/Inscriber | ||
* @createdOn : 11/14/2020 | ||
* @description : This is the File System. This handles all the Log File's | ||
* Methods | ||
* @since 11/15/2020 | ||
* @since : 11/21/2020 | ||
*========================================================================**/ | ||
import { Config } from "./global"; | ||
import { existsSync, readFileSync, writeFileSync, mkdirSync } from "fs"; | ||
|
@@ -17,12 +17,20 @@ export class FileSystem { | |
private _filename: string; | ||
private _content: string; | ||
private _config: Config; | ||
private _type: "ERROR" | "DEBUG" | "INFO" | "WARN"; | ||
constructor(config: Config, filename: string, content: string, type: "ERROR" | "DEBUG" | "INFO" | "WARN") { | ||
private _logType?: string; | ||
private _type: "ERROR" | "DEBUG" | "INFO" | "WARN" | "LOG"; | ||
constructor( | ||
config: Config, | ||
filename: string, | ||
content: string, | ||
type: "ERROR" | "DEBUG" | "INFO" | "WARN" | "LOG", | ||
logType?: string, | ||
) { | ||
this._filename = filename; | ||
this._content = content; | ||
this._config = config; | ||
this._type = type; | ||
this._logType = logType; | ||
} | ||
|
||
private checkIfPathExist() { | ||
|
@@ -39,6 +47,10 @@ export class FileSystem { | |
case "WARN": | ||
if (existsSync(`${this._config["log-paths"].warn}`)) return true; | ||
return false; | ||
case "LOG": | ||
if (existsSync(`${this._config["custom-logs"].find((x) => x.name == this._logType)?.path}`)) | ||
return true; | ||
return false; | ||
default: | ||
throw new TypeError(`${typeof this._type} is not a valid type.`); | ||
} | ||
|
@@ -59,6 +71,16 @@ export class FileSystem { | |
case "WARN": | ||
if (existsSync(`${this._config["log-paths"].warn}/${this._filename}`)) return true; | ||
return false; | ||
case "LOG": | ||
if ( | ||
existsSync( | ||
`${this._config["custom-logs"].find((x) => x.name == this._logType)?.path}/${ | ||
this._filename | ||
}`, | ||
) | ||
) | ||
return true; | ||
return false; | ||
default: | ||
throw new TypeError(`${typeof this._type} is not a valid type.`); | ||
} | ||
|
@@ -102,6 +124,22 @@ export class FileSystem { | |
} | ||
if (existsSync(`${this._config["log-paths"].warn}/${this._filename}`)) return true; | ||
return false; | ||
case "LOG": | ||
let _____path = ""; | ||
for (let dir of this._config["custom-logs"].find((x) => x.name == this._logType)?.path.split("/") ?? | ||
"") { | ||
_____path += dir; | ||
if (!existsSync(_____path)) mkdirSync(_____path); | ||
if ( | ||
existsSync( | ||
`${this._config["custom-logs"].find((x) => x.name == this._logType)?.path}/${ | ||
this._filename | ||
}`, | ||
) | ||
) | ||
return true; | ||
return false; | ||
} | ||
default: | ||
throw new TypeError(`${typeof this._type} is not a valid type.`); | ||
} | ||
|
@@ -139,6 +177,20 @@ export class FileSystem { | |
___data += "\n" + this._content; | ||
writeFileSync(`${this._config["log-paths"].warn}/${this._filename}`, ___data, { flag: "w" }); | ||
break; | ||
case "LOG": | ||
let ____data = readFileSync( | ||
`${this._config["custom-logs"].find((x) => x.name == this._logType)?.path}/${this._filename}`, | ||
{ | ||
encoding: "utf-8", | ||
}, | ||
); | ||
____data += "\n" + this._content; | ||
writeFileSync( | ||
`${this._config["custom-logs"].find((x) => x.name == this._logType)?.path}/${this._filename}`, | ||
____data, | ||
{ flag: "w" }, | ||
); | ||
break; | ||
} | ||
} else { | ||
switch (this._type) { | ||
|
@@ -186,6 +238,17 @@ export class FileSystem { | |
flag: "w", | ||
}); | ||
break; | ||
case "LOG": | ||
let _____message = | ||
new InscriberSystem().getAsciiName() + | ||
" -------------------------------------------" + | ||
`\n-----------------------------------------|${this._logType?.toUpperCase()} LOG FILE OF ${moment().format()}|------------------------------------------------` + | ||
"\n -------------------------------------------" + | ||
`\n${this._content}`; | ||
writeFileSync(`${this._config["log-paths"].warn}/${this._filename}`, _____message, { | ||
flag: "w", | ||
}); | ||
break; | ||
} | ||
} | ||
} | ||
|
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 |
---|---|---|
|
@@ -2,11 +2,11 @@ | |
* ? ABOUT | ||
* @author : Cody Spratford | ||
* @email : [email protected] | ||
* @repo : | ||
* @repo : https://github.com/koreanpanda345/Inscriber | ||
* @createdOn : 11/14/2020 | ||
* @description : This is Inscriber. Inscriber is NPM Logging Package | ||
* that is fully customizable. | ||
* @since : 11/15/2020 | ||
* @since : 11/21/2020 | ||
* @license | ||
* Copyright 2020 Cody Spratford. All Rights Reserved. | ||
* | ||
|
@@ -18,6 +18,7 @@ | |
* IMPORTS | ||
*========================**/ | ||
import { ErrorClass, InfoClass, DebugClass, WarnClass } from "./classes/exports"; | ||
import { LogMethod } from "./classes/Log"; | ||
import { Config } from "./global"; | ||
import { InscriberConfig } from "./InscriberConfig"; | ||
/**====================== | ||
|
@@ -144,4 +145,8 @@ export class Inscriber { | |
require.main?.filename == undefined ? "" : require.main?.filename, | ||
); | ||
} | ||
|
||
log(content: any, type: string): void { | ||
new LogMethod(new InscriberConfig().loadConfig(), content, require.main?.filename ?? "", type); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -2,18 +2,19 @@ | |
* ? ABOUT | ||
* @author : Cody Spratford | ||
* @email : [email protected] | ||
* @repo : | ||
* @repo : https://github.com/koreanpanda345/Inscriber | ||
* @createdOn : 11/14/2020 | ||
* @description : This is the Config file of Inscriber. This handles | ||
* loading, creating, and adding configurations to "inscriber.config.json". | ||
* @since : 11/21/2020 | ||
*========================================================================**/ | ||
|
||
import { existsSync, readFileSync, writeFileSync, readdirSync } from "fs"; | ||
import { Config } from "./global"; | ||
import { InscriberSystem } from "./InscriberSystem"; | ||
|
||
export class InscriberConfig { | ||
private _test_cases = readdirSync("./test"); | ||
private _test_cases = ["test", "test_1", "test_2", "test_3", "test_4", "test_5", "test_6"]; | ||
// SECTION DefaultConfig | ||
/**====================================================================== | ||
* DEFAULT CONFIG | ||
|
@@ -62,7 +63,8 @@ export class InscriberConfig { | |
background: "yellow", | ||
}, | ||
}, | ||
"time-pattern": "MMMM Do YYYY, h:mm:ss a", // Time formatting. | ||
"custom-logs": [], | ||
"time-pattern": "MMMM DD YYYY, h:mm:ss a", // Time formatting. | ||
}; | ||
// !SECTION | ||
/**======================= | ||
|
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 |
---|---|---|
|
@@ -2,11 +2,12 @@ | |
* ? ABOUT | ||
* @author : Cody Spratford | ||
* @email : [email protected] | ||
* @repo : | ||
* @repo : https://github.com/koreanpanda345/Inscriber | ||
* @createdOn : 11/14/2020 | ||
* @description : This is the System file. This is not for public use. | ||
* This is just for welcome message, and other stuff to inform the user about | ||
* something. | ||
* @since : 11/14/2020 | ||
*========================================================================**/ | ||
import chalk = require("chalk"); | ||
|
||
|
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,51 @@ | ||
/**======================================================================== | ||
* ? ABOUT | ||
* @author : Cody Spratford | ||
* @email : [email protected] | ||
* @repo : https://github.com/koreanpanda345/Inscriber | ||
* @createdOn : 11/21/2020 | ||
* @description : This is a builder for custom loggers. | ||
* @since : 11/21/2020 | ||
*========================================================================**/ | ||
|
||
import { CustomLogConfig } from "../global"; | ||
|
||
export class CustomLogBuilder { | ||
private _config: CustomLogConfig; | ||
constructor() { | ||
this._config = { | ||
name: "", | ||
aliases: [], | ||
path: "", | ||
color: { text: "", background: "" }, | ||
pattern: "", | ||
}; | ||
} | ||
|
||
setName(name: string): CustomLogBuilder { | ||
this._config.name = name; | ||
return this; | ||
} | ||
|
||
setAliases(aliases: string[]): CustomLogBuilder { | ||
this._config.aliases = aliases; | ||
return this; | ||
} | ||
|
||
setPath(path: string): CustomLogBuilder { | ||
this._config.path = path; | ||
return this; | ||
} | ||
|
||
setPattern(pattern: string): CustomLogBuilder { | ||
this._config.pattern = pattern; | ||
return this; | ||
} | ||
setColor(color: { text: string; background: string }): CustomLogBuilder { | ||
this._config.color = color; | ||
return this; | ||
} | ||
build(): CustomLogConfig { | ||
return this._config; | ||
} | ||
} |
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 |
---|---|---|
|
@@ -2,16 +2,18 @@ | |
* ? ABOUT | ||
* @author : Cody Spratford | ||
* @email : [email protected] | ||
* @repo : | ||
* @repo : https://github.com/koreanpanda345/Inscriber | ||
* @createdOn : 11/14/2020 | ||
* @description : This is the Config Builder. This Class can be used | ||
* to make the config to be applied when creating the config file. | ||
* @since : 11/21/2020 | ||
*========================================================================**/ | ||
/**======================= | ||
* IMPORT | ||
*========================**/ | ||
import { Config } from "../global"; | ||
import { Config, CustomLogConfig } from "../global"; | ||
import { InscriberConfig } from "../InscriberConfig"; | ||
import { CustomLogBuilder } from "./CustomLogBuilder"; | ||
/**======================= | ||
* END OF IMPORTS | ||
*========================**/ | ||
|
@@ -171,6 +173,12 @@ export class InscriberConfigBuilder { | |
}; | ||
return this; | ||
} | ||
|
||
addCustomLog(logConfig: CustomLogConfig): InscriberConfigBuilder { | ||
this.config["custom-logs"].push(logConfig); | ||
return this; | ||
} | ||
|
||
// !SECTION Log Paths | ||
// SECTION Build | ||
/**======================================================================== | ||
|
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 +1,11 @@ | ||
/**======================================================================== | ||
* ? ABOUT | ||
* @author : Cody Spratford | ||
* @email : [email protected] | ||
* @repo : https://github.com/koreanpanda345/Inscriber | ||
* @createdOn : 11/14/2020 | ||
* @description : This is the builders barrel file. | ||
* @since : 11/21/2020 | ||
*========================================================================**/ | ||
export * from "./InscriberConfigBuilder"; | ||
export * from "./CustomLogBuilder"; |
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 |
---|---|---|
|
@@ -2,10 +2,11 @@ | |
* ? ABOUT | ||
* @author : Cody Spratford | ||
* @email : [email protected] | ||
* @repo : | ||
* @repo : https://github.com/koreanpanda345/Inscriber | ||
* @createdOn : 11/14/2020 | ||
* @description : This is the Debug Class. This handles all debug type's | ||
* methods | ||
* @since : 11/15/2020 | ||
*========================================================================**/ | ||
|
||
import chalk = require("chalk"); | ||
|
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 |
---|---|---|
|
@@ -2,10 +2,11 @@ | |
* ? ABOUT | ||
* @author : Cody Spratford | ||
* @email : [email protected] | ||
* @repo : | ||
* @repo : https://github.com/koreanpanda345/Inscriber | ||
* @createdOn : 11/14/2020 | ||
* @description : This is the Error Class. This handles all the error type's | ||
* methods. | ||
* @since : 11/15/2020 | ||
*========================================================================**/ | ||
import chalk = require("chalk"); | ||
import moment = require("moment"); | ||
|
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 |
---|---|---|
|
@@ -2,10 +2,11 @@ | |
* ? ABOUT | ||
* @author : Cody Spratford | ||
* @email : [email protected] | ||
* @repo : | ||
* @repo : https://github.com/koreanpanda345/Inscriber | ||
* @createdOn : 11/14/2020 | ||
* @description : This is the Info Class. This handles all the info type's | ||
* methods. | ||
* @since : 11/15/2020 | ||
*========================================================================**/ | ||
|
||
import chalk = require("chalk"); | ||
|
@@ -32,10 +33,23 @@ export class InfoClass implements ILog { | |
} | ||
this.print(content.toString(), source, config); | ||
} | ||
/**============================================== | ||
* @summary Writes to the warn logs to the log files. | ||
* @param content - The warn log | ||
* @param source - the source of the warn log. | ||
* @param filepath - the file location for the log. | ||
* @param config - The configuration of Inscriber. | ||
*=============================================**/ | ||
write(content: string, source: string, filepath: string, config: Config): void { | ||
let message = this.formatString(config, source, content); | ||
new FileSystem(config, `${moment().format("YYYY_MM_D")}.log`, message, "INFO").write(); | ||
} | ||
/**============================================== | ||
* @summary Prints the warn log to the console. | ||
* @param content - the warn log. | ||
* @param source - The source of the warn log. | ||
* @param config - the configuration of Inscriber. | ||
*=============================================**/ | ||
print(content: string, source: string, config: Config): void { | ||
let message = this.formatString(config, source, content); | ||
|
||
|
Oops, something went wrong.