Giter Club home page Giter Club logo

node-eventlog's Introduction

node-eventlog

An event log utility for Windows 10 & Server 2012/2016 that actually works

node-eventlog is a lightweight C++ based module for Node.js, exclusive for the Windows operating systems, that provides functionality for writing entries to the Event Logs.

I created this module after finding a lack of existing supported packages that provided functionality for writing to the Windows Event Logs.

Compatibility

This module is written using NAPI, for compatibility with future versions of Node. It’s been tested with 64-bit Node 12.8 on 64-bit Windows 10 & Server 2012/2016- although, it should work with other installments of Node/Windows.

Installing

I made installing this package really simple utilizing a really cool module called node-pre-gyp. I’m able to host the pre-compiled binaries, here on GitHub, as releases.

To install, simply use the npm package:

npm i node-eventlog

However, if there is an issue installing the pre-compiled binaries (such as being behind a corporate firewall), it will fallback to compiling from the source, which means you need to have windows-build-tools or Visual Studio & Python installed.

How to use the module

Something I love about TypeScript is that my definitions file tells you everything you really need to know:

export type Severity = "info" | "warn" | "error";

export declare class EventLog {
    public readonly source: string;

    constructor(source: string);

    log(message: string, severity?: Severity, code?: number): Promise<boolean>;
}

Simply import the class, and create a new instance. The constructor requires a source, which is the name of the application that will be displayed in the Event Log entry.

The .log() method will write a new entry to the Application logs. You can optionally provide the type of log entry to write (info [default], warn, error), as well as an event code (default is 1000).

Note: the .log() method is Asynchronous

const { EventLog } = require(‘node-eventlog’);

const AppName = ‘MyTestApp’;

const Test = async () => {
    const logger = new EventLog(AppName);
    console.log(await logger.log(‘Test Message’, ‘info’, 9999));
};

Test();

Suggestions?

There are several other features that could potentially be added such as writing to other sections of the Event Logs or being able to read previous entries. Open a new issue if there’s something you’d like to see added!

node-eventlog's People

Contributors

xslither avatar sparist avatar

Watchers

 avatar

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.