log-gen

1.0.4 • Public • Published

Log Gen

This is a configurable script for generating dummy log file output.

Example Usage

The script can be used by the CLI command log-gen. This expects three arguments, an interval, set of amounts and a line format.

For example if you want to generate 5 lines every second (1000ms), where the line contains a random sentence with between 10 and 20 words, you would use this command:

log-gen -i 1000 -a [5] -f "{lorem(10,20)}"

To understand the timing parameters and generator syntax more, read the following two sections.

Outputting to a File

This script simply sends all of its output to stdout. So to capture it as an actual log file you can simply redirect the stdout using > or >>. For example:

log-gen -i 1000 -a [5] -f "{lorem(10,20)}" > ./MyLogFile.log

Timing Configuration

You can specify an interval and a set of amounts of lines to be generated throughout that interval.

For example with an interval of "1000" (ms, so 1 second) and an amounts set of "[2,5]", two lines will be output randomly within the first second and five lines will be output within the next second. This repeats until the process is killed.

Further Examples

  • Eg: 10 lines per second consistently is: -i 1000 -a [10]
  • Eg: 10 and 50 lines per second alternating is: -i 1000 -a [10,50]
  • Eg: 80 lines per second with bursts of 500 lines per second every fifth seconds is: -i 1000 -a [80,80,80,80,500]

Generator Functions

Within the given format argument you can use the generator syntax to produce randomly created content for each line. This format is {name(some,parameters)}, where name is one of the predefined (below) generator functions and the parameters are a comma-separated list of parameters to be passed to the function.

Generator functions are quite simple JavaScript functions, so if you think of one that should be added, feel free to raise an issue or PR on GitHub to suggest it.

Generator Function Names and Parameters

  • {date(format)} - The date at time of the line output, formatted based on the parameter
  • {ip()} - Generates an IP address
  • {choices(some,options)} - Randomly selects one of the parameters passed
  • {range(min,max)} - Generates a number in the range min..max
  • {lorem(min,max)} - Generates a sentence with an amount of words based on min and max
  • {camel(min,max)} - Generates a list of words formatted in PascalCase. Min and max effects the amount of words output.
  • {pascal(min,max)} - Generates a list of words formatted in camelCase. Min and max effects the amount of words output.

Readme

Keywords

none

Package Sidebar

Install

npm i log-gen

Weekly Downloads

2

Version

1.0.4

License

MIT

Last publish

Collaborators

  • rosscourt