Go to file
2021-05-08 22:24:00 +02:00
.vscode V3 2021-05-08 21:47:00 +02:00
src Add exports 2021-05-08 22:24:00 +02:00
.editorconfig Also adding prefix to browser console output 2020-03-21 21:13:46 +01:00
.gitignore Add ESModule support 2020-08-26 11:55:57 +02:00
deno_build.js V3 2021-05-08 21:47:00 +02:00
meta.json Add exports 2021-05-08 22:24:00 +02:00
package.json Add exports 2021-05-08 22:24:00 +02:00
README.md V3 2021-05-08 21:47:00 +02:00
tsconfig.esm.json Add ESModule support 2020-08-26 11:55:57 +02:00
tsconfig.json Add ESModule support 2020-08-26 11:55:57 +02:00

Logging

Simple logging module, that supports terminal coloring and different plugins

Getting Started

const Logging = require("@hibas123/logging").default;

Logging.log("Hello there");

There are different Logging levels, that also apply terminal coloring:

Logging.debug("Debug message");
Logging.log("Log message");
Logging.warning("Warning");
Logging.error(new Error("To less creativity"));
Logging.error("Just an simple message as error");
Logging.errorMessage("Nearly the same as error");

All Logging types except the simple error take as many arguments as you want. These will be joined with spaces and serialized with the node util.inspect function.

Setup

This logging module doesn't require any setup per default, but sometimes it makes sense to configure a few things.

For example can you disable the console output. This may be helpful, if you insert a custom adapters as described below.

Also you can set a name. All messages that are send with this instance are prefixed by this name.

const CustomLogging = new LoggingBase(
   name |
      {
         name: "custom", // default undefined
         console: false, // default true
      }
);

Plugins

There is a Plugin API available, that makes is possible to add custom Logging Adapter.

const Demo = new LoggingBase("Demo");
Demo.addAdapter(new DemoAdapter({ color: "rainbow" }));

The adapters need to provide a very simple Interface:

interface Adapter {
   init(): void | Promise<void>;

   onMessage(message: Message): void;

   flush(sync: true): void;
   flush(sync: false): void | Promise<void>;
}

interface Message {
   type: LoggingTypes;
   names?: string[];
   text: IFormatted;
   date: Date;
   file: string;
}

export interface IFormatted {
   color?: IColors;
   bgcolor?: IColors;
   bold?: boolean;
   italic?: boolean;
   blink?: boolean;
   underscore?: boolean;

   content: string;
}

enum LoggingTypes {
   Log,
   Warning,
   Error,
   Debug,
}

License

MIT

Copyright (c) 2018 Fabian Stamm

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.