1
0
mirror of https://git.stamm.me/OpenServer/NodeLogging.git synced 2024-11-13 06:21:05 +00:00
Go to file
2023-11-22 21:47:24 +01:00
.yarn Add ESM Module support 2023-10-14 16:54:53 +02:00
src Huge performance improvement through better queue system. 2021-05-19 13:50:04 +02:00
.editorconfig Updating dependencies 2020-03-21 21:13:54 +01:00
.gitattributes Add ESM Module support 2023-10-14 16:54:53 +02:00
.gitignore Add ESM Module support 2023-10-14 16:54:53 +02:00
.yarnrc.yml Add ESM Module support 2023-10-14 16:54:53 +02:00
package-lock.json Huge performance improvement through better queue system. 2021-05-19 13:50:04 +02:00
package.json Export module entrypoint 2023-11-22 21:47:24 +01:00
readme.md Updating Dependencies 2019-10-12 12:47:53 +02:00
tsconfig.esm.json Add ESM Module support 2023-10-14 16:54:53 +02:00
tsconfig.json First Commit 2017-08-23 16:45:03 +02:00

Simple logging module, that supports terminal coloring and writing to files.

This module build ontop of @hibas123/logging.

It extends the default behavior to support Logging to Files out of the Box.

Getting Started


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

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

NodeLogging can work without any configuration, but it may be useful to change the log output folder.

To do so you are capable of creating own instances of the LoggingBase class

   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

To not use any logfiles just set files to false.

Plugins

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

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

The adapters need to provide a very simple Interface:

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

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.