Giter VIP home page Giter VIP 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

Stargazers

 avatar

Watchers

 avatar

node-eventlog's Issues

Fails to build on arm64

Although this package is Windows-specific, there is no easy way in NPM to enable platform-specific dependencies. Instead, node-eventlog should handle non-Windows platforms without breaking.

Here is the error log when building on Raspberry Pi, which is an ARM64 Linux system:

> [email protected] install /home/gitlab-runner/builds/1yUs8yoP/0/Distributed-Compute-Protocol/dcp-native/artifacts/node/dcp-service/node_modules/node-eventlog
605> node-pre-gyp install --fallback-to-build --target_arch=x64 --target_platform=win32
606node-pre-gyp WARN Using request for node-pre-gyp https download 
607  SOLINK_MODULE(target) Release/obj.target/node-eventlog.node
608g++: error: unrecognized command-line option ‘-m64’
609make[4]: *** [node-eventlog.target.mk:22: Release/obj.target/node-eventlog.node] Error 1
610gyp ERR! build error 
611gyp ERR! stack Error: `make` failed with exit code: 2
612gyp ERR! stack     at ChildProcess.onExit (/usr/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:194:23)
613gyp ERR! stack     at ChildProcess.emit (events.js:400:28)
614gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:285:12)
615gyp ERR! System Linux 5.15.0-1015-raspi
616gyp ERR! command "/usr/bin/node" "/usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "build" "--fallback-to-build" "--target_arch=x64" "--target_platform=win32" "--module=/home/gitlab-runner/builds/1yUs8yoP/0/Distributed-Compute-Protocol/dcp-native/artifacts/node/dcp-service/node_modules/node-eventlog/lib/binding/napi-v2/node-eventlog.node" "--module_name=node-eventlog" "--module_path=/home/gitlab-runner/builds/1yUs8yoP/0/Distributed-Compute-Protocol/dcp-native/artifacts/node/dcp-service/node_modules/node-eventlog/lib/binding/napi-v2" "--napi_version=8" "--node_abi_napi=napi" "--napi_build_version=2" "--node_napi_label=napi-v2"
617gyp ERR! cwd /home/gitlab-runner/builds/1yUs8yoP/0/Distributed-Compute-Protocol/dcp-native/artifacts/node/dcp-service/node_modules/node-eventlog
618gyp ERR! node -v v14.20.1
619gyp ERR! node-gyp -v v5.1.0
620gyp ERR! not ok 
621node-pre-gyp ERR! build error 
622node-pre-gyp ERR! stack Error: Failed to execute '/usr/bin/node /usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js build --fallback-to-build --target_arch=x64 --target_platform=win32 --module=/home/gitlab-runner/builds/1yUs8yoP/0/Distributed-Compute-Protocol/dcp-native/artifacts/node/dcp-service/node_modules/node-eventlog/lib/binding/napi-v2/node-eventlog.node --module_name=node-eventlog --module_path=/home/gitlab-runner/builds/1yUs8yoP/0/Distributed-Compute-Protocol/dcp-native/artifacts/node/dcp-service/node_modules/node-eventlog/lib/binding/napi-v2 --napi_version=8 --node_abi_napi=napi --napi_build_version=2 --node_napi_label=napi-v2' (1)
623node-pre-gyp ERR! stack     at ChildProcess.<anonymous> (/home/gitlab-runner/builds/1yUs8yoP/0/Distributed-Compute-Protocol/dcp-native/artifacts/node/dcp-service/node_modules/node-pre-gyp/lib/util/compile.js:83:29)
624node-pre-gyp ERR! stack     at ChildProcess.emit (events.js:400:28)
625node-pre-gyp ERR! stack     at maybeClose (internal/child_process.js:1088:16)
626node-pre-gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:296:5)
627node-pre-gyp ERR! System Linux 5.15.0-1015-raspi
628node-pre-gyp ERR! command "/usr/bin/node" "/home/gitlab-runner/builds/1yUs8yoP/0/Distributed-Compute-Protocol/dcp-native/artifacts/node/dcp-service/node_modules/.bin/node-pre-gyp" "install" "--fallback-to-build" "--target_arch=x64" "--target_platform=win32"
629node-pre-gyp ERR! cwd /home/gitlab-runner/builds/1yUs8yoP/0/Distributed-Compute-Protocol/dcp-native/artifacts/node/dcp-service/node_modules/node-eventlog
630node-pre-gyp ERR! node -v v14.20.1
631node-pre-gyp ERR! node-pre-gyp -v v0.17.0
632node-pre-gyp ERR! not ok 
633Failed to execute '/usr/bin/node /usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js build --fallback-to-build --target_arch=x64 --target_platform=win32 --module=/home/gitlab-runner/builds/1yUs8yoP/0/Distributed-Compute-Protocol/dcp-native/artifacts/node/dcp-service/node_modules/node-eventlog/lib/binding/napi-v2/node-eventlog.node --module_name=node-eventlog --module_path=/home/gitlab-runner/builds/1yUs8yoP/0/Distributed-Compute-Protocol/dcp-native/artifacts/node/dcp-service/node_modules/node-eventlog/lib/binding/napi-v2 --napi_version=8 --node_abi_napi=napi --napi_build_version=2 --node_napi_label=napi-v2' (1)
634npm ERR! code ELIFECYCLE
635npm ERR! errno 1
636npm ERR! [email protected] install: `node-pre-gyp install --fallback-to-build --target_arch=x64 --target_platform=win32`
637npm ERR! Exit status 1
638npm ERR! 
639npm ERR! Failed at the [email protected] install script.
640npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
641npm ERR! A complete log of this run can be found in:
642npm ERR!     /home/gitlab-runner/.npm/_logs/2022-09-29T17_28_34_217Z-debug.log

A fix is forthcoming that disables the build on non-Windows systems and removes Windows-specific platform/architecture node-pre-gyp options.

Install fails on Windows 10, Node 12.21.0: "options.callback is not a function"

Attempting to install node-eventlog on Node 12.21.0 causes the following error:

node-pre-gyp WARN Using request for node-pre-gyp https download
node-pre-gyp ERR! UNCAUGHT EXCEPTION
node-pre-gyp ERR! stack TypeError: options.callback is not a function
node-pre-gyp ERR! stack     at Request.<anonymous> (C:\...\node_modules\request\main.js:290:21)
node-pre-gyp ERR! stack     at Request.emit (events.js:314:20)
node-pre-gyp ERR! stack     at IncomingMessage.<anonymous> (C:\...\node_modules\request\main.js:278:54)
node-pre-gyp ERR! stack     at IncomingMessage.emit (events.js:326:22)
node-pre-gyp ERR! stack     at endReadableNT (_stream_readable.js:1241:12)
node-pre-gyp ERR! stack     at processTicksAndRejections (internal/process/task_queues.js:84:21)
node-pre-gyp ERR! System Windows_NT 10.0.19042
node-pre-gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\...\\node_modules\\node-pre-gyp\\bin\\node-pre-gyp" "install" "--fallback-to-build" "--target_arch=x64" "--target_platform=win32"
node-pre-gyp ERR! cwd C:\...\node_modules\node-eventlog
node-pre-gyp ERR! node -v v12.21.0
node-pre-gyp ERR! node-pre-gyp -v v0.17.0
node-pre-gyp ERR! This is a bug in `node-pre-gyp`.
node-pre-gyp ERR! Try to update node-pre-gyp and file an issue if it does not help:
node-pre-gyp ERR!     <https://github.com/mapbox/node-pre-gyp/issues>

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.