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

@eyeseetea/d2-logger

v1.1.0

Published

DHIS2 library that allows a certain application to register logs as events in a DHIS2 event program, tracker program or simply display logs on the console.

Downloads

9

Readme

d2-logger

DHIS2 library that allows a certain application to register logs as events in a DHIS2 event program, tracker program or simply display logs on the console.

Usage

There are three types of logger output:

  1. Using a DHIS2 events program to register the logs as events:

    You will need to have and existing event program in DHIS2 with the following data elements with value type Text: Message and MessageType. MessageType would be and option set with the following options: "Error", "Warn", "Success", "Info" and "Debug".

    Therefore, the following configuration will be passed to the logger:

    import { initLogger, ProgramLogger } from "@eyeseetea/d2-logger";
    
    const logger: ProgramLogger = await initLogger({
        type: "program",
        debug: true,
        baseUrl: "https://play.dhis2.org/40.2.2",
        auth: {
            username: "admin",
            password: "district",
        },
        organisationUnitId: "", // Organisation unit Id where the program is registered
        programId: "", // Event program Id where register the logs as events
        dataElements: {
            messageId: "", // Id of the data element which is the message
            messageTypeId: "", // Id of the data element which is the types of message
        },
    });

    Notice:

    • Please note that auth is not mandatory if it's used in the DHIS2 app instead of in a script.
    • If debug is true, then in addition to registering the logs in the DHIS2 program, they will also be displayed on the console.

    To log messages as single events:

    logger.debug("This is a Debug message");
    logger.info("This is an Info message");
    logger.success("This is a Success message");
    logger.warn("This is a Warn message");
    logger.error("This is an Error message");

    To log messages in batch and create several events at once:

    logger.batchLog([
        { content: "This is a Debug message", messageType: "Debug" },
        { content: "This is a Info message", messageType: "Info" },
        { content: "This is a Success message", messageType: "Success" },
        { content: "This is a Warn message", messageType: "Warn" },
        { content: "This is a Debug message", messageType: "Error" },
    ]);
  2. Displaying the logs only in the console:

    import { initLogger, ConsoleLogger } from "@eyeseetea/d2-logger";
    
    const logger: ConsoleLogger = await initLogger({
        type: "console",
    });

    To log messages:

    logger.debug("This is a Debug message");
    logger.info("This is an Info message");
    logger.success("This is a Success message");
    logger.warn("This is a Warn message");
    logger.error("This is an Error message");

    To log messages in batch:

    logger.batchLog([
        { content: "This is a Debug message", messageType: "Debug" },
        { content: "This is a Info message", messageType: "Info" },
        { content: "This is a Success message", messageType: "Success" },
        { content: "This is a Warn message", messageType: "Warn" },
        { content: "This is a Debug message", messageType: "Error" },
    ]);
  3. Using a DHIS2 tracker program to register the logs as events:

    You will need to have and existing tracker program in DHIS2. In order to be able to log the log type (Error", "Warn", "Success", "Info" and "Debug") in the event, it would be necessary to create a data element and assign it to the program stages, and then add this data element id to the configuration.

    Therefore, the following configuration will be passed to the logger:

    import { initLogger, TrackerProgramLogger } from "@eyeseetea/d2-logger";
    
    const logger: TrackerProgramLogger = await initLogger({
        type: "trackerProgram",
        debug: true,
        baseUrl: "https://play.dhis2.org/40.2.2",
        auth: {
            username: "admin",
            password: "district",
        },
        trackerProgramId: "", // Tracker program Id where register the logs as events
        messageTypeId: "", // Id of the data element which is the types of log
    });

    Notice:

    • Please note that auth is not mandatory if it's used in the DHIS2 app instead of in a script.
    • If debug is true, then in addition to registering the logs in the DHIS2 program, they will also be displayed on the console.
    • messageTypeId is not mandatory. If the log type is not provided, "Error", "Warn", "Success", "Info" and "Debug" will not be logged in the event.

    To log messages:

    logger.debug({
        config: {
            trackedEntityId: "", // Tracked entity Id where register the logs as events
            programStageId: "", // Program Stage Id where register the logs as events
            enrollmentId: "", // Enrollment Id where register the logs as events
            eventStatus: "", // event status by default is "ACTIVE" if not specified, but it can also be "COMPLETED", "VISITED", "SCHEDULE", "OVERDUE" or "SKIPPED"
        },
        messages: [
            {
                id: "", // Data Element Id of the Data Value of the event to be logged
                value: "This is a Debug message",
            },
        ],
    });
    
    logger.info({
        config: {
            trackedEntityId: "", // Tracked entity Id where register the logs as events
            programStageId: "", // Program Stage Id where register the logs as events
            enrollmentId: "", // Enrollment Id where register the logs as events
            eventStatus: "", // event status by default is "ACTIVE" if not specified, but it can also be "COMPLETED", "VISITED", "SCHEDULE", "OVERDUE" or "SKIPPED"
        },
        messages: [
            {
                id: "", // Data Element Id of the Data Value of the event to be logged
                value: "This is an Info message",
            },
        ],
    });
    
    logger.success({
        config: {
            trackedEntityId: "", // Tracked entity Id where register the logs as events
            programStageId: "", // Program Stage Id where register the logs as events
            enrollmentId: "", // Enrollment Id where register the logs as events
            eventStatus: "", // event status by default is "ACTIVE" if not specified, but it can also be "COMPLETED", "VISITED", "SCHEDULE", "OVERDUE" or "SKIPPED"
        },
        messages: [
            {
                id: "", // Data Element Id of the Data Value of the event to be logged
                value: "This is a Success message",
            },
        ],
    });
    
    logger.warn({
        config: {
            trackedEntityId: "", // Tracked entity Id where register the logs as events
            programStageId: "", // Program Stage Id where register the logs as events
            enrollmentId: "", // Enrollment Id where register the logs as events
            eventStatus: "", // event status by default is "ACTIVE" if not specified, but it can also be "COMPLETED", "VISITED", "SCHEDULE", "OVERDUE" or "SKIPPED"
        },
        messages: [
            {
                id: "", // Data Element Id of the Data Value of the event to be logged
                value: "This is a Warn message",
            },
        ],
    });
    
    logger.error({
        config: {
            trackedEntityId: "", // Tracked entity Id where register the logs as events
            programStageId: "", // Program Stage Id where register the logs as events
            enrollmentId: "", // Enrollment Id where register the logs as events
            eventStatus: "", // event status by default is "ACTIVE" if not specified, but it can also be "COMPLETED", "VISITED", "SCHEDULE", "OVERDUE" or "SKIPPED"
        },
        messages: [
            {
                id: "", // Data Element Id of the Data Value of the event to be logged
                value: "This is an Error message",
            },
        ],
    });

    Notice:

    • messages is an array of objects with the id of the Data Element and a string value. These would be created as Data Values in the event.
    • eventStatus is not mandatory. By deafult "ACTIVE" will be the default status of the event.

Development

$ nvm use # Selects node in .nvmrc
$ yarn install
$ yarn build
$ cd build
$ yarn link

On another app:

$ yarn link "@eyeseetea/d2-logger"

Tests

$ yarn test

Code quality

$ yarn code-quality

Publish

First, change in package.json the new version and then run:

$ yarn release