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

app-logs

v3.0.0

Published

Módulo de logs

Downloads

45

Readme

Módulo logs

Creación, búsqueda y listado de logs, el guardado de logs se puede escoger entre base de datos o sistema de archivos:

  1. Logs en base de datos (por defecto): Registra los logs en una tabla con Sequelize, Postgresql y GraphQL.
  2. Logs en sistema de archivos: Registra los logs en un archivo del sistema de archivos.
  3. Logs en consola: Manda los logs también a la salida estándar (stdout) y cuando son de nivel error los manda a stderr.

Maneja tres niveles de logs: info, warning, error.

LICENCIA: MIT License (Omar Gutiérrez C.)

Requisitos

  • Nodejs 7.6 en adelante

Modo de uso

# Instalando librería
npm install app-logs --save

Instanciando el módulo logs en un proyecto, primero hay que definir un objeto de configuración:

const Logs = require('app-logs');

// en caso de usar logs en el sistema de archivos se usa:
const config = {
  logsConfig: {
    // indica que los logs se guardan en el sistema de archivos
	// posibles: 'filesystem', 'database'
    storage: 'filesystem',

    // para mostrar los logs también en la consola (stdout) esto debería ser true
	// Cuando se loguea con nivel 'error' el log va a stderr en lugar de stdout
    console: false,

    // directorio con los logs
    outputDirectory: './logs',

    // nombre de archivo de logs
    outputFilename: 'logs.log',

    // formato de logs, con algunas de las opciones de winston (combined, interpolation, json)
    format: 'combined',

    // nivel de logs por defecto, posibles: error, info, warning. (info por defecto)
    level: 'info'
  }
};

// en caso de usar logs en base de datos bastaría:
const config = {
  database: 'postgres',
  username: 'postgres',
  password: 'postgres',
  host: 'localhost',
};

Luego iniciar el módulo.

const logs = await Logs(config).catch(err => console.error(err));

Uso

// Message error
await logs.error('Message error');

// Message info
await logs.info('Message info');

// Message warning
await logs.warning('Message warning');

// Pasando el nivel de logs manualmente se pueden agregar detalles: 
// - Mensaje: String - Texto del mensaje
// - Nivel de logs: String solo con los valores "info", "warn" o "error"
// - tipo: String - Tipo de log (sirve para hacer búsquedas)
// - Referencia: String - Mas detalle del mensaje (sirve para hacer búsquedas)
// - Usuario: String - Guardar con el nombre de un usuario
// - Ip: String - Dirección ip
await logs.log('Mensaje', 'info', 'API','ref-0', 'usuario1', '1.0.0.1');
await logs.log('Mensaje de advertencia', 'warn', 'GRAPHQL','ref-0', 'usuario', '1.0.0.1');
await logs.log('Mensaje de error', 'error', 'ref-0', 'DATABASE', 'usuario', '1.0.0.1');

// guardara usando el nivel de logs por defecto y las demás opciones vacías
await logs.log('Mensaje');

// logs.[info|error|warning](mensaje, tipo, referencia, usuario, ip)
// todos los parámetros son opcionales menos 'mensaje', ej.
logs.info('Mensaje de info', 'ACTUALIZACIÓN');
logs.error('Mensaje de error, 'ACTUALIZACIÓN', 'Doc con id 100', '', '10.100.122.125');

Ver más ejemplos de uso en tests.

Consultar logs:

// Lista completa de logs, puede recibir parámetros de búsqueda entre otras opciones
let list = await logs.findAll();

// Lista de logs por nivel 'info'
list = await logs.findAll({ level: 'info'});

// Lista de logs por dirección ip 127.0.0.1
list = await logs.findAll({ ip: '127.0.0.1'});

Ver más ejemplos de uso en tests/.

Ejecutando indivualmente

Siga los siguientes pasos:

# 1. Instalar dependencias
npm install

# 2. Correr test de prueba, configurar la variable config con la conexión de la base de datos
# en el archivo src/util.js
npm test