4.0.1 • Published 7 months ago

loggerfunction v4.0.1

Weekly downloads
-
License
ISC
Repository
-
Last release
7 months ago

Simple loggerfunction with File Name and Line Number

A lightweight utility function to enhance console.log by logging the file name and line number automatically.

Features

  • Automatically logs the file name and line number where the log is called.
  • No need to manually modify each console.log.
  • Useful for debugging large projects.

Installation

Install the package via npm:

npm install loggerfunction

Or via yarn:

yarn add loggerfunction

Note for TypeScript Users

If you are using TypeScript, make sure to enable source maps in your tsconfig.json file to ensure accurate file names and line numbers are displayed:

{
  "compilerOptions": {
    "sourceMap": true
  }
}

Usage

Import the loggerfunction

import { log } from "loggerfunction";

Example Code

import { log } from "loggerfunction";

function greet(name: string) {
  log("Hello,", name);
}

function add(a: number, b: number) {
  log("Adding numbers:", a, b);
  return a + b;
}

greet("World");
add(5, 3);
log("This is a standalone log");

Output

When you run the code, the output will display the file name and line number dynamically:

[filename:line-number] Hello, World
[filename:line-number] Adding numbers: 5 3
[filename:line-number] This is a standalone log

How It Works

The log function uses the stack trace to determine the file name and line number where it was called.

Use Cases

  • Debugging: Easily identify where log statements are being called.
  • Large Projects: Quickly trace logs without searching through files.
  • Error Tracking: Provides more context for debugging errors.

License

MIT

3.0.3

8 months ago

3.0.2

8 months ago

3.0.1

8 months ago

3.0.0

8 months ago

2.0.2

8 months ago

4.0.1

7 months ago

4.0.0

8 months ago

2.0.1

8 months ago

2.0.0

8 months 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