npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

logger-files

v1.3.6

Published

Logger with files structure and automatic update by days without turning off

Downloads

10

Readme

LOGGER

Simple crossplatform logger with output in file system to node.js projects

  • Output in console with color message
  • Simplify config

EXAMPLES

CONFIG

Logs in console differ in types: database, application, logs. To change name for each use next syntax:

import Logger from './logger.js';
const logger = new Logger({ application: 'SERVER' }); // you can change this from define
logger.database = 'database'; // or from property of entity

You can also use config file like this:

const logger = new Logger();
// logger.json.config
{
    "application": "SERVER",
    "database": "DATABASE",
    "logger": "LOGGER",
}

To change default config file (file need to be in json format):

const logger = new Logger({ config: 'your_config_file' });

FILES

In default logger output in files in 'logs' directory in root directory of project. To change this option:

const logger = new Logger({ logDir: 'loggerDEF' });
logger.logDir = 'loggerSTR'
{
    "logDir": "loggerJSON"
}

After create entity of logger logDir will create automatically. Logger write in every day in format DD-MM-YY. How to log:

  • For log from your application-server use server(...message)
  • For log from your database-wrapper use database(...message)
  • For log from your auth-service use login(username, userData = { ip: '127.0.0.1'}) This methods create separated files with TIME, MESSAGE format
  • database create and using database.csv
  • server create and using server.csv
  • login create and using auth.csv
// example
logger.server('Server started');
logger.database('Database connection established');
logger.login('user123', { ip: '127.0.0.1', role: 'user' }); // for example u can add personal field in log
logger.login('user123', { password: '123' }); // why u doing this?
// CUSTOM FILES
// methods follow naming rules like regular variables (bad: 1no, 123, #asd) 
// be carefull while using names: server, database, login
// if you don’t follow these rules, the method won’t do anything.
logger.custom('auth.log'); // filename and data 
// and after this u can use this file easy 
logger.auth('123'); // method = filename without extension which u use in custom log 
// and you can use this
logger.custom('auth.log', 'test'); // set custom name for method
logger.test('123'); // append '123' to auth.log

UPDATE

By default config logger create dir everyday and logger can do it without rebooting system:

  • Logger check system time for installed interval
  • Logger if system time is less than set time interval ago (it means tomorrow has come) create new directory and start working on it

Logger by default have interval for this action - 2 minutes. It can be changed:

// firstly need to set for need update
// warning 1: this means that application will be infinity interval loop
// warning 2: without set update 
// first way:
// setter of 'update' supports dynamic attribute change, this allows you to turn the interval on and off at any time
logger.update = true;
// second way:
new Logger({ update: true });
// third way:
{
    "update": true
}
// after that you can change interval time (in ms)
// it is not recommended to use a small amount of time, it can cause a lot of stress of PC
// first way:
new Logger({ updateTime: 120000 });
// second way:
{
    "updateTime": 123456789
}
// third way (unrecommended for development): 
// that canceling current interval and start new
logger.updateTime = 22222;

WATCHING LOGS

For get all files in last

const files = await logger.listLogs(); // output array of files from THIS day
const files = await logger.listLogs('060524'); // output array of files from 0605024 
/*
example output in console: Logs/060524: auth.log, authlogs.csv, custom_authlogs.csv, database.csv, error.csv, server.csv
files = 
[
  'auth.log',
  'authlogs.csv',
  'custom_authlogs.csv',
  'database.csv',
  'error.csv',
  'server.csv'
]
*/

Also logger have method to read logs it's implemented from async methods using head -n and tail -n with exec for files

logger.headLog('auth.log'); // output 10 from top of file
logger.tailLog('auth.log'); // output 10 from end of file 
logger.outputLog('auth.log'); // output all file
// output from given date
logger.headLog('auth.log', '060524');
logger.tailLog('auth.log', '060524');
logger.outputLog('auth.log', '060524');