2.0.7 • Published 1 year ago

@maxpp/processlogger v2.0.7

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year 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

1 year ago

2.0.6

1 year ago

2.0.5

1 year ago

2.0.4

1 year ago

2.0.3

1 year ago

2.0.2

1 year ago

2.0.1

1 year ago

1.0.47

1 year ago

1.0.45

1 year ago

1.0.44

1 year ago

1.0.43

1 year ago

1.0.42

1 year ago

1.0.41

1 year ago

1.0.40

1 year ago

1.0.39

1 year ago

1.0.38

1 year ago

1.0.37

1 year ago

1.0.33

1 year ago

1.0.32

1 year ago

1.0.31

1 year ago

1.0.30

1 year ago

1.0.29

1 year ago

1.0.28

1 year ago

1.0.27

1 year ago

1.0.26

1 year ago

1.0.25

1 year ago

1.0.24

1 year ago

1.0.23

1 year ago

1.0.22

1 year ago

1.0.21

1 year ago

1.0.20

1 year ago

1.0.19

1 year ago

1.0.18

1 year ago

1.0.17

1 year ago

1.0.16

1 year ago

1.0.15

1 year ago

1.0.14

1 year ago

1.0.13

1 year ago

1.0.12

1 year ago

1.0.11

1 year ago

1.0.10

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago