2.0.7 • Published 2 years ago

@maxpp/processlogger v2.0.7

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

Process Log

A logging function for used to log steps of a process.

  • The ideal is to leave the logs in your code and enable or disable them as needed by changing the log property in your Log.start() call.
  • This is useful to quickly log the flow of a process when developing or debugging, and other developers can easily enable or disable the logs to see the process running.

Features:

  • Start and end new process logs with a name.
  • Easily enable or disable logging for a specific process.
  • Clearly logs steps of a process and logs the duration of the process.
  • Proces logs are colored for easy identification. The colors are randomly assigned per process, or you can set a specific color per process.

Installation

  npm i @maxpp/processlogger

Import

  import { Log } from "@maxpp/processlogger";

Usage

Log.start({ name: "myProcess", log: true }); // Start the process by naming it and decide if it should log.
Log.log.myProcess("Message to log"); // Log a message within the process.
Log.end.myProcess(); // Stop the process and log the duration.

Example

Log.start({ name: "myProcess", log: true }); // Start the process. Set log to false to disable logging.
Log.log.myProcess("Creating data source"); // Log a message
Log.log.myProcess("SUCCESS - Fetched data source template");
Log.log.myProcess("Parsed data source template");
Log.end.myProcess(); // End the process and log the duration

Example output

----- START - MYPROCESSNAME -----
myProcess: Creating data source
myProcess: SUCCESS - Fetched data source template /process.ts:12
myProcess: SUCCESS - Fetched data set template /process.ts:12
myProcess: Parsed data source template /process.ts:12
myProcess: Parsed data set template /process.ts:12
----- END - MYPROCESSNAME - Completed in 1.46 seconds. -----

Example log output

This example shows the process logs of 5 processes that run in sequence. Each process is asigned a random color when it starts which makes it easier to distinguish the logs of each process.

  • updated_project_blocks (This operation logged in blue and completed in 0.062 seconds.)
  • created_project_validation (This operation logged in salmon and did not complete.)
  • update_project_queue (This operation logged in purple and did not complete.)
  • update_project_s3_files (This operation logged in fushia and completed in 0.954 seconds.)
  • get_content_from_s3 (This operation logged in green and completed in 0.494 seconds.)

Disable a process log

Set the log property to false to disable logging for a specific process. This way you can leave the logs in your code and enable them as needed.

Log.start({ name: "datasource", log: false }); // Set log to false to disable logging.

Set a specific color for a process

You can set a specific hex color for a process by passing a color property in the start method.

Log.start({ name: "datasource", log: true, color: "#2a9d8f" }); // Set a specific color for the process.

V2 Changes

  • The process name is now added after the .log or .end. Example: Log.log.myProcess("Message to log"); or Log.end.myProcess();
  • The function can now be imported with Log instead of ProcessLog.
  • The log messages now display the file and line number where the log was called.
  • Optional color property to set a specific color for a process.

Recommended use

  • Add clear operation logs for each of your processes and leave them in your code.
  • Once implemented, disabled the operation logs by setting the log property to false.
  • During development or debugging, other team members can easily enable the logs to immediately see the process runnign and identify any issues.

Dependencies

  • chalk - For colored console output.
2.0.7

2 years ago

2.0.6

2 years ago

2.0.5

2 years ago

2.0.4

2 years ago

2.0.3

2 years ago

2.0.2

2 years ago

2.0.1

2 years ago

1.0.47

2 years ago

1.0.45

2 years ago

1.0.44

2 years ago

1.0.43

2 years ago

1.0.42

2 years ago

1.0.41

2 years ago

1.0.40

2 years ago

1.0.39

2 years ago

1.0.38

2 years ago

1.0.37

2 years ago

1.0.33

2 years ago

1.0.32

2 years ago

1.0.31

2 years ago

1.0.30

2 years ago

1.0.29

2 years ago

1.0.28

2 years ago

1.0.27

2 years ago

1.0.26

2 years ago

1.0.25

2 years ago

1.0.24

2 years ago

1.0.23

2 years ago

1.0.22

2 years ago

1.0.21

2 years ago

1.0.20

2 years ago

1.0.19

2 years ago

1.0.18

2 years ago

1.0.17

2 years ago

1.0.16

2 years ago

1.0.15

2 years ago

1.0.14

2 years ago

1.0.13

2 years ago

1.0.12

2 years ago

1.0.11

2 years ago

1.0.10

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago