Working toward web compatibility

- Separating File output from LoggingBasse
- Separating Console output from LoggingBase
- Adding new Plugin mechanism
This commit is contained in:
Fabian Stamm
2019-03-23 16:50:12 +01:00
parent dec35001e3
commit 58ff2fd2ea
9 changed files with 2994 additions and 305 deletions

View File

@ -30,20 +30,66 @@ NodeLogging can work without any configuration, but it may be useful to change t
Todo so you are capable of creating own instances of the LoggingBase class
``` javascript
const CustomLogging = new LoggingBase({
name: "custom",
logfile: "./logs/test.log",
errorfile: "/var/log/custom.err",
console_out: false
const CustomLogging = new LoggingBase(name | {
name: "custom", // default undefined
files: true | false | { //default true
logfile: "./logs/test.log",
errorfile: "/var/log/custom.err",
}
console: false // default true
});
```
The name property prefixes the console output with the name. Also if no logfile or errorfile is created the following standard values are used:
./logs/all.{name}.log
./logs/error.{name}.log
- ./logs/all.{name}.log
- ./logs/error.{name}.log
To not use any logfiles just set files to false.
# Plugins
There is a new Plugin API available, that makes is possible to add custom Logging Adapter.
``` javascript
const Demo = new LoggingBase("Demo");
Demo.addAdapter(new DemoAdapter({ color: "rainbow" }));
```
The adapters need to provide a very simple Interface:
``` typescript
interface Adapter {
init(observable: ObservableInterface<Message>, name?: string): void | Promise<void>;
flush(sync: true): void;
flush(sync: false): void | Promise<void>;
}
interface Message {
type: LoggingTypes;
name?:string;
text: {
raw: string[],
formatted: string[]
};
date: Date;
file: string;
customColors?:string;
}
enum LoggingTypes {
Log,
Warning,
Error,
Debug
}
```
The `ObservableInterface` comes from `@hibas123/utils`. It provides a very simple api for subscribing and unsubscribing from the message events.
More Details on Observable [here](https://git.stamm.me/OpenServer/Utils)
To not use any logfiles just set the values to null.
# License
MIT