Coder Social home page Coder Social logo

astrologger's Introduction

astrologger's People

Contributors

expertrix avatar

Watchers

Alexander Ivanov avatar

Forkers

expertrix

astrologger's Issues

Possible bug with flush

Describe the problem

Flush should lock itself until write end to avoid parallel data flush.

lock = false;
const flush = () => {
 if(lock) return;
 lock = true;
 //... some flush logic
 stream.write(buffer, () => {
   lock = false;
   //... other release logic
 }) 
}

Logger v1.0.0 setup

Describe the problem

Logger v1.0.0

Configuration

Types and structure of possible logger configuration:

// ?: means unnecessary or can be default value
const options: {
  path?: string; // Absolute or relative path, by default no logs into files
  keep?: number; // delete after N days, 0 - disable, (default: 1 if path specified else 0)
  home?: string; // Remove that part from Error paths.
  mark?: string; // Some additional information for the logs
  logLevel?: number; // Disable logs under this log level
  timeFormat?: string; // Stdout time format (default: h:m:s)
  write?: { // Write settings
    consoleMethod?: (...args: any) => void; // console.log or process.stdout.write (default: console.log)
    interval?: [number, number] | number, // flush log to disk and console intervals (default: 300ms)
    buffer?: number, // buffer size (default: 64kb)
  };
  methods?: { // Console methods
    // ...defaultMethods
    info?: { // By default all console methods
      color: string; // R;G;B (default: 255;255;255) or some gray color
      level?: number; // Important level (default: 0), bigger = more important.
      parser?: (...args: any) => [string, string] | string; // Custom message parser, [stdout, file] | universal
      callback?: async (...args: any) => void; // Custom callback function, can be used to provide logs to other API.
    }
    // Can be new methods such as myOwnLogMethod
  };
};

Usage

My vision of logger usage:

const Logger = require('astrolog');

// Possible configuration
const opts = {
  path: './log',
  keep: 5,
  home: process.cwd(),
  mark: 'Worker №7',
  logLevel: 0,
  timeFormat: 'd:m:s.i', // i means millisecond
  write: {
    interval: [300, 3000],
    buffer: 64 * 1024,
    consoleMethod: process.stdout.write
  },
  methods: {
    myOwnLogMethod: [
      color: "0;0;255",
      level: 3,
      parser: (message) => message + ' custom handler',
      callback: (message) => {},
    ]
  }
}

(async () => {
  const logger = await Logger.open(opts); // Static method
  // const logger = await new Logger(opts) Or standard way

  const { console } = logger;
  console.log('Test message');
  console.error('Error message');
  // All console methods
  // For the start - log, error, clear, dir, table, warn, info, debug, assert

  await logger.close();
})();

Describe the solution

No response

Alternatives

No response

Additional context

More about some console methods

Methods console.error and console.debug

This methods should parse thrown error to make Errors more readable.

For example

const Logger = require('astrolog');
const console = Logger(/* Some options */);
console.error(new Error('Testing console.error')); 
// Error: Testing console.error /path/to/executable-file.js:row:column

In configuration we have home options, its allow us to remove this part of path from Error.

Additional

Would be great if repeated messages will be replaced by message + counter

For example

const Logger = require('astrolog');
const console = Logger(/* Some options */);
console.error(new Error('Testing console.error')); 
console.error(new Error('Testing console.error')); 
console.error(new Error('Testing console.error')); 
// ... old messages, before first log
// Error: Testing console.error /path/to/executable-file.js:row:column #3

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.