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

seneca-logtrans-plugin

v1.0.4

Published

internal plugin to transform and process log entries of seneca instances.

Downloads

6

Readme

seneca-logtrans-plugin

npm version Build Status Coveralls

This is an internal plugin to transform and process log entries of seneca instances.

The plugin is based on the custom_logger example, given to the seneca itself.

The purpose of this plugin to gain direct control of the logging of seneca, in order to better understand, how it is working. This plugin also provide a naive but efficient way to control what and how to print out during development and debugging.

Note: This plugin is tested with seneca v3.2.2

Prerequisites

No preprequisites.

Installation

Run the install command:

npm install

Run tests:

npm test

To obtain coverage, run:

npm coverage

Usage

It is preloaded during the initialization of the seneca instance, and can be configured directly through the instance options.

It has an adapter() function, which gets every log entry that is enabled to be processed (see the log config parameters of the instance).

The adapter does three simple things:

  1. Converts the user defined log entries into a normalized format, that is:
   {
        kind: 'user',
        when: <timestamp>,
        level: <log-level>,
        payload: <the user defined content>
   }
  1. If the filterFun is defined, then calls it with the normalized log entry as a parameter. If this function returns with false, then finishes the processing of the log entry. if true, then continues with step 3.
  2. If the processFun is defined, then calls it with the normalized log entry. This function defines actually what to do with the log entry (print, save, etc.).

To load the plugin:

This is an internal plugin, so do not load it via the seneca.use() function. Instead, define parameters for this via the options of the seneca instance, using the internal.logger property, as you can see in the example below.

See the lib/index.spec.js unit tests or the examples/logPropStats.js as an examples that demonstrate how to configure the plugin, and how to define simple functions to filter and process the log entries.

Options

The plugin has two optional configuration parameters:

  • filterFun: The filter function, which controls the further processing of the log entry. It gets the log entry as a parameter, and returns with a Boolean value: true continues processing, and false stops processing.
  • processFun: It gets the log entry as a parameter, and does whatever it wants with that.

The default options of the plugin:

    {
        filterFun: function(logEntry) { return true },
        processFun: function(logEntry) { console.log(logEntry) }
    }

So, in case none of the functions are defined the plugin simply prints out each log entry by default.

The following code snippet demonstrates how to configure the plugin through the seneca instance:

    const senecaLogTrans = require('seneca-logtrans-plugin')
    const _ = require('lodash')
    
    seneca({
        internal: {
            // Loads the plugin
            logger: senecaLogTrans
        },
        // These are the direct options of the plugin 
        'seneca-logtrans-plugin' : {
            filterFun: function(logEntry) { return _.includes(['act'], logEntry.kind) },
            processFun: function(logEntry) { log.push(logEntry); printLogEntry(logEntry) }
        },
        // Controls what to be forwarded to the adapter function
        log: {
            basic: "any"
        }
    })

You can find some examples under the examples folder.

The examples/logPropStats.js example script prints out a table to show the properties that are carried together with a specific kind of log entry.

The result shows that the possible values of the kind property of the log entry are: act | add | notice | options | plugin user. The rows visualize which log entry property can exist accompanied with a specified kind.

    node examples/logPropStats.js

                act       add       notice    options   plugin    user      
    actid        +                             +         +                  
    caller       +                                                          
    callpoint              +                   +         +                  
    case         +         +                   +         +                  
    client       +                                                          
    duration     +                                                          
    entry        +                                                          
    exports                                              +                  
    gate         +                                                          
    id                     +                                                
    kind         +         +         +         +         +         +        
    level        +         +         +         +         +         +        
    listen       +                                                          
    meta         +                                                          
    msg          +                                                          
    name                   +                             +                  
    notice                           +                                      
    options                          +         +         +                  
    pattern      +         +                   +         +                  
    payload                                                        +        
    plugin_name  +         +                   +         +                  
    plugin_tag   +         +                   +         +                  
    prior        +                                                          
    result       +                                                          
    seneca       +         +         +         +         +         +        
    tag                                                  +                  
    transport    +                                                          
    when         +         +         +         +         +         +

The examples/logPropStats.js example demonstrates how to filter and format the seneca log to make the whole process easier to follow. The configuration is placed into the examples/logCfgs.js file.

    node examples/logFormatter.js

    [-/transport/-] act     IN      name:transport,plugin:define,role:seneca,seq:1,tag:undefined
    msg:
        name: transport
        plugin: define
        role: seneca
        seq: 1

    _________________________________________

    [-/transport/-] act     DEFAULT name:transport,plugin:define,role:seneca,seq:1,tag:undefined
    msg:
        init: transport

    _________________________________________


    ...

Actions

The plugin provides no action.

References


This project was generated from the seneca-plugin-archetype by the kickoff utility.