Script 'mail_helper' called by obssrc Hello community, here is the log from the commit of package logfilegen for openSUSE:Factory checked in at 2023-02-07 18:48:59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/logfilegen (Old) and /work/SRC/openSUSE:Factory/.logfilegen.new.4462 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "logfilegen" Tue Feb 7 18:48:59 2023 rev:3 rq:1063467 version:1.1.0 Changes: -------- --- /work/SRC/openSUSE:Factory/logfilegen/logfilegen.changes 2023-02-01 16:47:48.336752652 +0100 +++ /work/SRC/openSUSE:Factory/.logfilegen.new.4462/logfilegen.changes 2023-02-07 18:49:06.823140907 +0100 @@ -1,0 +2,8 @@ +Mon Feb 6 16:37:10 UTC 2023 - Andreas Stieger <[email protected]> + +- logfilegen 1.1.0: + * slightly faster + * Adds new macros for combining several commands into one (@meta) and + for using sequences as a macro (@seq). + +------------------------------------------------------------------- Old: ---- logfilegen-1.0.0.tar.gz New: ---- logfilegen-1.1.0.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ logfilegen.spec ++++++ --- /var/tmp/diff_new_pack.TUP3j5/_old 2023-02-07 18:49:07.371143853 +0100 +++ /var/tmp/diff_new_pack.TUP3j5/_new 2023-02-07 18:49:07.379143896 +0100 @@ -18,7 +18,7 @@ Name: logfilegen -Version: 1.0.0 +Version: 1.1.0 Release: 0 Summary: Log file generator for server log files and user-defined formats License: Unlicense @@ -55,7 +55,7 @@ %files %license LICENSE %doc ChangeLog README.md -%doc docs/config.md docs/templates.md templates/* +%doc docs/config.md docs/templates.md %{_bindir}/logfilegen %changelog ++++++ logfilegen-1.0.0.tar.gz -> logfilegen-1.1.0.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/logfilegen-1.0.0/.github/workflows/cmake.yml new/logfilegen-1.1.0/.github/workflows/cmake.yml --- old/logfilegen-1.0.0/.github/workflows/cmake.yml 1970-01-01 01:00:00.000000000 +0100 +++ new/logfilegen-1.1.0/.github/workflows/cmake.yml 2023-02-06 16:09:14.000000000 +0100 @@ -0,0 +1,37 @@ +name: CMake + +on: workflow_dispatch +# push: +# branches: [ "main" ] +# pull_request: +# branches: [ "main" ] + +env: + # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) + BUILD_TYPE: Release + +jobs: + build: + # The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac. + # You can convert this to a matrix build if you need cross-platform coverage. + # See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix + runs-on: ubuntu-latest, windows-latest, macos-latest + + steps: + - uses: actions/checkout@v3 + + - name: Configure CMake + # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. + # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type + run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} + + - name: Build + # Build your program with the given configuration + run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} + +# - name: Test +# working-directory: ${{github.workspace}}/build + # Execute tests defined by the CMake configuration. + # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail + #run: ctest -C ${{env.BUILD_TYPE}} + diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/logfilegen-1.0.0/.github/workflows/xbuild.yml new/logfilegen-1.1.0/.github/workflows/xbuild.yml --- old/logfilegen-1.0.0/.github/workflows/xbuild.yml 1970-01-01 01:00:00.000000000 +0100 +++ new/logfilegen-1.1.0/.github/workflows/xbuild.yml 2023-02-06 16:09:14.000000000 +0100 @@ -0,0 +1,29 @@ +# test +name: XBUILD + +on: [push,workflow_dispatch] + +jobs: + linux: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v1 + - name: Build + run: make + + windows: + runs-on: windows-latest + steps: + - name: Checkout + uses: actions/checkout@v1 + - name: Build + run: make + + macos: + runs-on: macos-latest + steps: + - name: Checkout + uses: actions/checkout@v1 + - name: Build + run: make diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/logfilegen-1.0.0/CMakeLists.txt new/logfilegen-1.1.0/CMakeLists.txt --- old/logfilegen-1.0.0/CMakeLists.txt 2023-01-30 15:52:47.000000000 +0100 +++ new/logfilegen-1.1.0/CMakeLists.txt 2023-02-06 16:09:14.000000000 +0100 @@ -2,7 +2,7 @@ set (CMAKE_CXX_STANDARD 17) -project (logfilegen VERSION 1.0.0 LANGUAGES CXX) +project (logfilegen VERSION 1.1.0 LANGUAGES CXX) add_definitions(-DVERSION_NUMBER="\\"${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}\\"") diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/logfilegen-1.0.0/ChangeLog new/logfilegen-1.1.0/ChangeLog --- old/logfilegen-1.0.0/ChangeLog 2023-01-30 15:52:47.000000000 +0100 +++ new/logfilegen-1.1.0/ChangeLog 2023-02-06 16:09:14.000000000 +0100 @@ -1,3 +1,4 @@ ++ DESTDIR support + $protocol //corrected + $server_protocol diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/logfilegen-1.0.0/Makefile new/logfilegen-1.1.0/Makefile --- old/logfilegen-1.0.0/Makefile 2023-01-30 15:52:47.000000000 +0100 +++ new/logfilegen-1.1.0/Makefile 2023-02-06 16:09:14.000000000 +0100 @@ -14,10 +14,10 @@ $(RM) logfilegen uninstall: - rm $(prefix)/bin/logfilegen + rm $(DESTDIR)$(prefix)/bin/logfilegen install: logfilegen - install -m 0755 logfilegen $(prefix)/bin/logfilegen + install -m 0755 logfilegen $(DESTDIR)$(prefix)/bin/logfilegen test: logfilegen --help diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/logfilegen-1.0.0/Makefile.clang new/logfilegen-1.1.0/Makefile.clang --- old/logfilegen-1.0.0/Makefile.clang 2023-01-30 15:52:47.000000000 +0100 +++ new/logfilegen-1.1.0/Makefile.clang 2023-02-06 16:09:14.000000000 +0100 @@ -13,9 +13,9 @@ uninstall: - rm $(prefix)/bin/logfilegen + rm $(DESTDIR)$(prefix)/bin/logfilegen install: logfilegen - install -m 0755 logfilegen $(prefix)/bin + install -m 0755 logfilegen $(DESTDIR)$(prefix)/bin .PHONY: install diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/logfilegen-1.0.0/Makefile.static new/logfilegen-1.1.0/Makefile.static --- old/logfilegen-1.0.0/Makefile.static 2023-01-30 15:52:47.000000000 +0100 +++ new/logfilegen-1.1.0/Makefile.static 2023-02-06 16:09:14.000000000 +0100 @@ -13,10 +13,10 @@ $(RM) logfilegen uninstall: - rm $(prefix)/bin/logfilegen + rm $(DESTDIR)$(prefix)/bin/logfilegen install: logfilegen - install -m 0755 logfilegen $(prefix)/bin/logfilegen + install -m 0755 logfilegen $(DESTDIR)$(prefix)/bin/logfilegen test: logfilegen --help diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/logfilegen-1.0.0/NEWS new/logfilegen-1.1.0/NEWS --- old/logfilegen-1.0.0/NEWS 1970-01-01 01:00:00.000000000 +0100 +++ new/logfilegen-1.1.0/NEWS 2023-02-06 16:09:14.000000000 +0100 @@ -0,0 +1,12 @@ +What's new? +The new release is slighty faster. Two new macros were added: @meta and @seq. All of them are described at the documentation, here in a short - @meta allows to combine several macros into one, so we can use more than one macro at the simple (non-sequenced) variable value. And @seq can be used to use sequences at macro, as in the usual variable value. + +Example 001: + +$test=@seq:GET:PUT +$logstring=hello, $test + +Example 002: + +$test=@meta:foo (@str:12) bar (@int:12:16) (@ip) +$logstring=hello, $test diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/logfilegen-1.0.0/README.md new/logfilegen-1.1.0/README.md --- old/logfilegen-1.0.0/README.md 2023-01-30 15:52:47.000000000 +0100 +++ new/logfilegen-1.1.0/README.md 2023-02-06 16:09:14.000000000 +0100 @@ -12,12 +12,12 @@ [Dockerhub repo](https://hub.docker.com/r/psemiletov/logfilegen/general) -[AUR](https://aur.archlinux.org/packages/logfilegen) +[AUR](https://aur.archlinux.org/packages/logfilegen), [openSUSE](https://software.opensuse.org/package/logfilegen) ## ABOUT -Logfilegen is a fast and highly customizable tool to generate common server (nginx, etc) or user-defined format log files. You can generate log file with the desired rate (lines per second), the file size, lines count and the duration. Each variable of the log file can be redefined by the random or static value. logfilegen depends just on GCC or Clang with C++17 support, and, optionally, cmake. +Logfilegen is a fast and highly customizable tool to generate server (nginx, etc) or user-defined format log files. You can generate log file with the desired rate (lines per second), the file size, lines count and the duration. Each variable of the log file can be redefined by the random or static value. logfilegen depends just on GCC or Clang with C++17 support, and, optionally, cmake. ## USE diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/logfilegen-1.0.0/cycle.cpp new/logfilegen-1.1.0/cycle.cpp --- old/logfilegen-1.0.0/cycle.cpp 2023-01-30 15:52:47.000000000 +0100 +++ new/logfilegen-1.1.0/cycle.cpp 2023-02-06 16:09:14.000000000 +0100 @@ -2,13 +2,10 @@ #include <chrono> #include <iostream> - #include "cycle.h" using namespace std::chrono; - - namespace { volatile std::sig_atomic_t g_signal; @@ -58,7 +55,7 @@ test_string_size = test_string.size(); if (params->debug) - cout << "size_needed, bytes: " << size_needed << endl; + cout << "size_needed, bytes: " << size_needed << endl; if (size_needed >= free_space) { @@ -66,7 +63,6 @@ no_free_space = true; } } - } @@ -166,7 +162,7 @@ if (! params->pure) { if (params->bstdout) - cout << log_string << "\n"; + cout << log_string << "\n"; if (! file_out_error && ! no_free_space) { @@ -217,33 +213,33 @@ void CGenCycleUnrated::loop() { - auto start = high_resolution_clock::now(); + auto start = high_resolution_clock::now(); - size_t lines_counter = 0; + size_t lines_counter = 0; // using clock = std::chrono::steady_clock; - while (true) - { - if (g_signal == SIGINT) - break; + while (true) + { + if (g_signal == SIGINT) + break; - lines_counter++; + lines_counter++; - if (params->lines != 0 && lines_counter > params->lines) + if (params->lines != 0 && lines_counter > params->lines) break; - if (params->size != 0 && file_size_total > params->size) - break; + if (params->size != 0 && file_size_total > params->size) + break; - if (params->duration != 0) - { - auto stop = high_resolution_clock::now(); + if (params->duration != 0) + { + auto stop = high_resolution_clock::now(); // auto duration = duration_cast<microseconds>(stop - start); - auto duration_s = duration_cast<seconds>(stop - start); - if (duration_s >= chrono::seconds(params->duration)) - break; - } + auto duration_s = duration_cast<seconds>(stop - start); + if (duration_s >= chrono::seconds(params->duration)) + break; + } // std::cout << "seconds_counter: " << seconds_counter << endl; // std::cout << "frame_counter: " << frame_counter << endl; @@ -259,6 +255,7 @@ if (! file_out_error && ! no_free_space) { file_out << log_string << "\n"; + log_current_size += log_string.size(); file_size_total += log_string.size(); @@ -293,9 +290,6 @@ if (params->stats) { -// cout << "lines_counter : " << lines_counter << endl; -// cout << "duration_s.count : " << duration_s.count() << endl; - double lines_per_second = (double) lines_counter / duration_s.count(); cout << "Statistics, lines per seconds: " << lines_per_second << endl; } @@ -307,6 +301,5 @@ cout << "duration_s.count (seconds): " << duration_s.count() << endl; } - file_out.close(); } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/logfilegen-1.0.0/docs/config.md new/logfilegen-1.1.0/docs/config.md --- old/logfilegen-1.0.0/docs/config.md 2023-01-30 15:52:47.000000000 +0100 +++ new/logfilegen-1.1.0/docs/config.md 2023-02-06 16:09:14.000000000 +0100 @@ -69,7 +69,7 @@ All configuration variables from the configuration file can be **overriden** using command line options in the format ```--key=value```. For example: -```console +``` logfilegen --duration=3 ``` @@ -164,7 +164,7 @@ Generate 20000 lines per second, 10 seconds, with the default (built-in) nginx template, then stop: -```console +``` logfilegen --duration=10 --rate=20000 ``` @@ -174,7 +174,7 @@ Generate exactly 100000 with rate 20000 lines per second, with the default (built-in) nginx template, then stop: -```console +``` logfilegen --lines=100000 --rate=20000 ``` @@ -184,7 +184,7 @@ Generate 64 Mb lines, at full speed, with the default (built-in) nginx template, making log rotation using 4 log filesm each 1 Mb size: -```console +``` logfilegen --size=64M --logcount=4 --logsize=1M ``` @@ -193,7 +193,7 @@ Generate lines to stdout (console), in the infinity loop, and rate 10 lines per second, until breaked by Ctrl-C: -```console +``` logfilegen --rate=10 --logfile=stdout ``` diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/logfilegen-1.0.0/docs/index.md new/logfilegen-1.1.0/docs/index.md --- old/logfilegen-1.0.0/docs/index.md 2023-01-30 15:52:47.000000000 +0100 +++ new/logfilegen-1.1.0/docs/index.md 2023-02-06 16:09:14.000000000 +0100 @@ -4,13 +4,17 @@ ## LINKS -[Github repo](https://github.com/psemiletov/logfilegen) +[Github repo](https://github.com/psemiletov/logfilegen), [Latest release](https://github.com/psemiletov/logfilegen/releases/latest) [Dockerhub repo](https://hub.docker.com/r/psemiletov/logfilegen/general) -[AUR](https://aur.archlinux.org/packages/logfilegen) +[AUR](https://aur.archlinux.org/packages/logfilegen), [openSUSE](https://software.opensuse.org/package/logfilegen) +## NEWS + +***06 february 2023, 1.1.0*** - The new release is slighty faster. Two new macros were added: @meta and @seq. All of them are described at the documentation, here in a short - @meta allows to combine several macros into one, so we can use more than one macro at the simple (non-sequenced) variable value. And @seq can be used to use sequences at macro, as in the usual variable value. + ## MANUAL To install it, please read [Installation guide](inst.md) @@ -28,3 +32,5 @@ [Using configuration](config.md) [Using templates](templates.md) + +Written by Peter Semiletov, 2023 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/logfilegen-1.0.0/docs/templates.md new/logfilegen-1.1.0/docs/templates.md --- old/logfilegen-1.0.0/docs/templates.md 2023-01-30 15:52:47.000000000 +0100 +++ new/logfilegen-1.1.0/docs/templates.md 2023-02-06 16:09:14.000000000 +0100 @@ -228,7 +228,7 @@ Where, macro ```@path``` expands to the random-generated path with the path parts length randomly varied from 1 to 10, and depth from 1 to 3 -#### $file +#### @file Acts as the text file loader for **sequence** variable values. @@ -262,6 +262,35 @@ When processed, the ```@file:/home/test/testsource.txt``` directive will load ```/home/test/testsource.txt```, transform it to ```|```-separated values and choose one of them randomly. +#### @seq + +Works like **sequence** variable values. Each value is separated by ```:```. + +Syntax: ```@seq:param1:param2:etc``` + +Example: + +``` +$test=@seq:GET:PUT +$logstring=hello, $test +``` + + +#### @meta + +The macro for compound macros, to set the line with several macros as the variable value. Each macro in such compound macros must be placed to the braces. + +Syntax: ```@meta:(macro1)(macros)``` + +Example: + +``` +$test=@meta:foo (@str:12) bar (@int:12:16) (@ip) +$logstring=hello, $test +``` + +Such complex macro can contain the free form text among the macros. The nested @meta macros are not supported. + ### Complex examples diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/logfilegen-1.0.0/logrot.cpp new/logfilegen-1.1.0/logrot.cpp --- old/logfilegen-1.0.0/logrot.cpp 2023-01-30 15:52:47.000000000 +0100 +++ new/logfilegen-1.1.0/logrot.cpp 2023-02-06 16:09:14.000000000 +0100 @@ -37,7 +37,6 @@ if (has_gzip && use_gzip) { - for (size_t i = filenames.size() - 1; i > 0; i--) { string oldname = filenames[i-1] + ".gz"; @@ -58,4 +57,3 @@ } } } - diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/logfilegen-1.0.0/macro.cpp new/logfilegen-1.1.0/macro.cpp --- old/logfilegen-1.0.0/macro.cpp 2023-01-30 15:52:47.000000000 +0100 +++ new/logfilegen-1.1.0/macro.cpp 2023-02-06 16:09:14.000000000 +0100 @@ -25,7 +25,8 @@ string gen_string (std::mt19937 *rnd_generator, size_t len) { - ostringstream st; + string result; + result.reserve (128); std::uniform_int_distribution<> distrib (0, 25); @@ -33,16 +34,17 @@ { int g = distrib (*rnd_generator); char d = static_cast<char> (g + 'a'); - st << d; + result += d; } - return st.str(); + return result; } string gen_string (std::mt19937 *rnd_generator, size_t min, size_t max) { - ostringstream st; + string result; + result.reserve (128); std::uniform_int_distribution<> distrib (0, 25); std::uniform_int_distribution<> dminmax (min, max); @@ -52,16 +54,16 @@ { int g = distrib (*rnd_generator); char d = static_cast<char> (g + 'a'); - st << d; + result += d; } - return st.str(); + return result; } - string gen_rnd_path (std::mt19937 *rnd_generator, size_t min, size_t max, size_t deep) { string result; + result.reserve (256); size_t deep_max = get_rnd (rnd_generator, 1, deep); @@ -82,6 +84,7 @@ std::uniform_int_distribution<> distrib (0, 9); string result; + result.reserve (len); for (size_t i = 0; i < len; i++) { @@ -99,6 +102,7 @@ size_t len = dminmax (*rnd_generator); string result; + result.reserve (len); for (size_t i = 0; i < len; i++) { @@ -114,6 +118,7 @@ std::uniform_int_distribution<> distrib (0, 15); string result; + result.reserve (len); for (size_t i = 0; i < len; i++) { @@ -131,6 +136,7 @@ size_t len = dminmax (*rnd_generator); string result; + result.reserve (len); for (size_t i = 0; i < len; i++) { @@ -159,13 +165,15 @@ CMacrosPool::CMacrosPool() { - macros.insert (std::make_pair ("@ip", new CMacroIPRandom())); - macros.insert (std::make_pair ("@str", new CMacroStrRandom())); - macros.insert (std::make_pair ("@int", new CMacroIntRandom())); - macros.insert (std::make_pair ("@hex", new CMacroHexRandom())); - macros.insert (std::make_pair ("@datetime", new CMacroDateTime())); - macros.insert (std::make_pair ("@path", new CMacroPathRandom())); - macros.insert (std::make_pair ("@file", new CMacroFileSource())); + macros.insert (std::make_pair ("@ip", new CMacroIPRandom())); + macros.insert (std::make_pair ("@str", new CMacroStrRandom())); + macros.insert (std::make_pair ("@int", new CMacroIntRandom())); + macros.insert (std::make_pair ("@hex", new CMacroHexRandom())); + macros.insert (std::make_pair ("@datetime", new CMacroDateTime())); + macros.insert (std::make_pair ("@path", new CMacroPathRandom())); + macros.insert (std::make_pair ("@file", new CMacroFileSource())); + macros.insert (std::make_pair ("@meta", new CMacroMeta())); + macros.insert (std::make_pair ("@seq", new CMacroSeq())); } @@ -178,20 +186,40 @@ } +CMacrosPoolMeta::CMacrosPoolMeta() +{ + macros.insert (std::make_pair ("@ip", new CMacroIPRandom())); + macros.insert (std::make_pair ("@str", new CMacroStrRandom())); + macros.insert (std::make_pair ("@int", new CMacroIntRandom())); + macros.insert (std::make_pair ("@hex", new CMacroHexRandom())); + macros.insert (std::make_pair ("@datetime", new CMacroDateTime())); + macros.insert (std::make_pair ("@path", new CMacroPathRandom())); + macros.insert (std::make_pair ("@file", new CMacroFileSource())); + macros.insert (std::make_pair ("@seq", new CMacroSeq())); +} + + +CMacrosPoolMeta::~CMacrosPoolMeta() +{ + for (auto itr = macros.begin(); itr != macros.end(); ++itr) + { + delete (itr->second); + } +} + CMacroIPRandom* CMacroIPRandom::create_self (const string &s) { return new CMacroIPRandom(); - } - string CMacroIPRandom::process() { std::uniform_int_distribution<> distrib (0, 255); string result; + result.reserve (16); result += to_string (distrib (*rnd_generator)); result += "."; @@ -240,7 +268,7 @@ if (len_max == 0) return gen_string (rnd_generator, length); - return gen_string (rnd_generator, len_min, len_max); + return gen_string (rnd_generator, len_min, len_max); } @@ -276,11 +304,10 @@ if (len_max == 0) return gen_number (rnd_generator, length); - return gen_number (rnd_generator, len_min, len_max); + return gen_number (rnd_generator, len_min, len_max); } - CMacroHexRandom* CMacroHexRandom::create_self (const string &s) { CMacroHexRandom *m = new CMacroHexRandom(); @@ -313,11 +340,10 @@ if (len_max == 0) return gen_hex_number (rnd_generator, length); - return gen_hex_number (rnd_generator, len_min, len_max); + return gen_hex_number (rnd_generator, len_min, len_max); } - CMacroDateTime* CMacroDateTime::create_self (const string &s) { CMacroDateTime *m = new CMacroDateTime(); @@ -339,25 +365,6 @@ } -/* SLOW -string CMacroDateTime::process() -{ - if (text.empty()) - return string(); - - auto t = std::time (nullptr); - auto tm = *std::localtime(&t); - - std::ostringstream oss; - oss << std::put_time (&tm, text.c_str()); - - auto result = oss.str(); - return result; -} -*/ - - - string CMacroDateTime::process() { if (text.empty()) @@ -371,16 +378,12 @@ char buffer [128]; strftime (buffer, 128, text.c_str(), timeinfo); - //std::ostringstream oss; - //oss << std::put_time (&tm, text.c_str()); auto result = buffer; return result; } - - CMacroPathRandom* CMacroPathRandom::create_self (const string &s) { CMacroPathRandom *m = new CMacroPathRandom(); @@ -391,7 +394,6 @@ void CMacroPathRandom::parse (const string &s) { - len_min = 0; len_max = 0; length = 0; @@ -417,6 +419,70 @@ } +CMacroSeq* CMacroSeq::create_self (const string &s) +{ + CMacroSeq *m = new CMacroSeq(); + m->parse (s); + return m; +} + + +vector <string> split_string_to_vector_a (const string &s, char delimeter, char aware) +{ + vector <string> result; + + size_t a = 0; + size_t b = 0; + + while (b < s.size()) + { + if (b + 1 == s.size()) + { + string t = s.substr (a + 1, b - a); + result.push_back (t); + } + + if (s[b] == delimeter) + if (b + 1 != s.size()) + if (s[b + 1] != aware) + { + string t; + + if (a == 0) + t = s.substr (a, b - a); + else + t = s.substr (a + 1, b - a - 1); + + result.push_back (t); + a = b; + } + + b++; + } + + return result; +} + + +void CMacroSeq::parse (const string &s) +{ + len_min = 0; + len_max = 0; + length = 0; + text = ""; + + vt = split_string_to_vector_a (s, ':', '/'); +} + + +string CMacroSeq::process() +{ + size_t i = get_rnd (rnd_generator, 1, vt.size() - 1); + + return vt[i]; +} + + CMacroFileSource* CMacroFileSource::create_self (const string &s) { CMacroFileSource *m = new CMacroFileSource(); @@ -425,7 +491,6 @@ } - void CMacroFileSource::parse (const string &s) { len_min = 0; @@ -442,53 +507,132 @@ } +string CMacroFileSource::process() +{ + if (vt.size() != 0) + text = vt[get_rnd (rnd_generator, 0, vt.size()-1)]; -/* -void CMacroFileSource::parse (const string &s) + return text; +} + + +CMacroMeta* CMacroMeta::create_self (const string &s) { + CMacroMeta *m = new CMacroMeta(); + m->parse (s); + return m; +} + +void CMacroMeta::parse (const string &s) +{ len_min = 0; len_max = 0; length = 0; text = ""; + //оÑделÑем название макÑоÑа size_t pos = s.find (":"); - if (pos == string::npos) - return; + if (pos != string::npos) + text = s.substr (pos + 1); //after : + else + return; //check it - string path = s.substr (pos + 1); - string t1 = string_file_load (path); + // cout << "all text of macro: " << text << endl; - if (! t1.empty()) - { - string t2 = string_replace_all (t1, "\n", "|"); - t2 = string_replace_all (t2, "\r\n", "|"); //for windows - t2.pop_back(); //remove last | - - vector <string> v; //values - v = split_string_to_vector (t2, "|"); - - //vector <string> v = vector_file_load (path); - text = v[get_rnd (rnd_generator, 0, v.size()-1)]; - } + //иÑем вложеннÑе макÑоÑÑ + + size_t i = 0; + + while (i < text.size()) + { + if (text[i] == '(') //start of macro + { + // cout << "//start of macro" << endl; + + //search to ), then get macro text + size_t j = i; + + bool found = false; + + while (j < text.size()) + { + if (text[j] == ')') + { + found = true; + break; + } + + j++; + } + + + //now, macro text in between i and j + if (found) + { + string macrotext = text.substr (i, j-i + 1); + i += macrotext.size(); + + macrotext.pop_back(); + macrotext.erase (0, 1); + + // cout << "macrotext:" << macrotext << endl; + + //create cached macro + string name = get_macro_name (macrotext); + + // cout << "and name is: " << name << endl; + + if (name.empty()) + continue; + + auto f = pool.macros.find (name); + if (f == pool.macros.end()) + continue; + + //copy metamacro instead of real one + string newname = "@" + to_string(i); + + meta += newname; + + CMacro *tm = f->second->create_self (macrotext); + + cache.add (newname, tm); + } + } + + meta += text[i]; + i++; + } } -*/ -string CMacroFileSource::process() + +string CMacroMeta::process() { - //cout << "CMacroFileSource::process()" << endl; + text = meta; - if (vt.size() != 0) - text = vt[get_rnd (rnd_generator, 0, vt.size()-1)]; + map <string, CMacro*>::iterator it; + for (it = cache.macros.begin(); it != cache.macros.end(); it++) + { + string macroname = it->first; //@1, @2, etc + // cout << "macroname:" << macroname << endl; + size_t i = 0; + do + { + i = text.find (macroname); + if (i != string::npos) + text.replace (i, macroname.length(), it->second->process()); + } + while (i != string::npos); + } + // cout << "text:" << text << endl; return text; } - - void CMacrosCache::add (size_t pos, CMacro *m) { - macros.insert (std::make_pair (pos, m)); + macros.insert (std::make_pair (pos, m)); } @@ -496,6 +640,21 @@ { for (auto itr = macros.begin(); itr != macros.end(); ++itr) { + delete (itr->second); + } +} + + +void CMacrosCacheMeta::add (const string &s, CMacro *m) +{ + macros.insert (std::make_pair (s, m)); +} + + +CMacrosCacheMeta::~CMacrosCacheMeta() +{ + for (auto itr = macros.begin(); itr != macros.end(); ++itr) + { delete (itr->second); } } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/logfilegen-1.0.0/macro.h new/logfilegen-1.1.0/macro.h --- old/logfilegen-1.0.0/macro.h 2023-01-30 15:52:47.000000000 +0100 +++ new/logfilegen-1.1.0/macro.h 2023-02-06 16:09:14.000000000 +0100 @@ -10,6 +10,8 @@ using namespace std; +//class CMacrosPoolMeta; + class CMacro { public: @@ -17,6 +19,7 @@ std::random_device rnd_dev; string text; + string meta; //ÑоÑÑÐ¾Ð¸Ñ Ð¸Ð· @1 @2 .. size_t len_min; size_t len_max; @@ -27,6 +30,7 @@ virtual CMacro* create_self (const string &s) {return new CMacro();}; virtual string process() {return string ("CMacro::process()");}; virtual void parse (const string &s) {}; + virtual void interpet (const string &s) {}; }; @@ -98,6 +102,17 @@ }; +class CMacroSeq: public CMacro +{ +public: + vector <string> vt; + + CMacroSeq* create_self (const string &s); + string process(); + void parse (const string &s); + ~CMacroSeq(){}; +}; + class CMacroFileSource: public CMacro { @@ -113,6 +128,8 @@ + + class CMacrosPool { public: @@ -124,6 +141,17 @@ }; +class CMacrosPoolMeta +{ +public: + + map <string, CMacro*> macros; + + CMacrosPoolMeta(); + ~CMacrosPoolMeta(); +}; + + class CMacrosCache { public: @@ -131,10 +159,36 @@ map <int, CMacro*> macros; void add (size_t pos, CMacro *m); - //CMacrosPool(); ~CMacrosCache(); }; +class CMacrosCacheMeta +{ +public: + + map <string, CMacro*> macros; + + void add (const string &s, CMacro *m); + ~CMacrosCacheMeta(); +}; + + + +class CMacroMeta: public CMacro +{ +public: + + CMacrosPoolMeta pool; + CMacrosCacheMeta cache; + + vector <string> vt; + + CMacroMeta* create_self (const string &s); + string process(); + void parse (const string &s); + ~CMacroMeta(){}; +}; + #endif diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/logfilegen-1.0.0/main.cpp new/logfilegen-1.1.0/main.cpp --- old/logfilegen-1.0.0/main.cpp 2023-01-30 15:52:47.000000000 +0100 +++ new/logfilegen-1.1.0/main.cpp 2023-02-06 16:09:14.000000000 +0100 @@ -18,7 +18,7 @@ #ifndef VERSION_NUMBER -#define VERSION_NUMBER "1.0.0" +#define VERSION_NUMBER "1.1.0" #endif diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/logfilegen-1.0.0/pairfile.cpp new/logfilegen-1.1.0/pairfile.cpp --- old/logfilegen-1.0.0/pairfile.cpp 2023-01-30 15:52:47.000000000 +0100 +++ new/logfilegen-1.1.0/pairfile.cpp 2023-02-06 16:09:14.000000000 +0100 @@ -2,7 +2,6 @@ * this code by Peter Semiletov is Public Domain * **********************************************************/ - #include <fstream> #include <iostream> #include <sstream> @@ -11,7 +10,6 @@ #include <cstring> #include <algorithm> - #include "pairfile.h" #include "utl.h" @@ -98,7 +96,7 @@ int result = def_value; if (values.find (key) == values.end()) - return result; + return result; const char *s = values[key].c_str(); if (s) @@ -107,43 +105,6 @@ return result; } -/* -unsigned int CPairFile::get_uint (const string &key, unsigned int def_value) -{ - unsigned int result = def_value; - - if (values.find (key) == values.end()) - return result; - - const char *s = values[key].c_str(); - if (! s) - return result; - - char* end; - result = strtoul (s, &end, 10); - - return result; -} -*/ -/* -unsigned long long CPairFile::get_uulong (const string &key, unsigned long long def_value) -{ - unsigned long long result = def_value; - - if (values.find (key) == values.end()) - return result; - - const char *s = values[key].c_str(); - if (! s) - return result; - - char* end; - result = strtoull (s, &end, 10); - - return result; -} -*/ - size_t CPairFile::get_num (const string &key, unsigned long long def_value) { @@ -267,7 +228,7 @@ continue; } - if (pos > line.size()) //???? + if (pos >= line.size()) continue; string a = line.substr (0, pos); diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/logfilegen-1.0.0/pairfile.h new/logfilegen-1.1.0/pairfile.h --- old/logfilegen-1.0.0/pairfile.h 2023-01-30 15:52:47.000000000 +0100 +++ new/logfilegen-1.1.0/pairfile.h 2023-02-06 16:09:14.000000000 +0100 @@ -23,7 +23,6 @@ bool get_bool (const string &key, bool def_value = false); int get_int (const string &key, int def_value = 0); -// unsigned int get_uint (const string &key, unsigned int def_value = 0); size_t get_num (const string &key, unsigned long long def_value = 0); float get_float (const string &key, float def_value = 0.0f); diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/logfilegen-1.0.0/params.cpp new/logfilegen-1.1.0/params.cpp --- old/logfilegen-1.0.0/params.cpp 2023-01-30 15:52:47.000000000 +0100 +++ new/logfilegen-1.1.0/params.cpp 2023-02-06 16:09:14.000000000 +0100 @@ -14,7 +14,7 @@ cout << "lines: " << lines << endl; cout << "logfile: " << logfile << endl; cout << "logsize: " << max_log_file_size << endl; - cout << "max_log_files: " << max_log_files << endl; + cout << "logfiles: " << max_log_files << endl; cout << "mode: " << mode << endl; cout << "pure: " << pure << endl; cout << "rate: " << rate << endl; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/logfilegen-1.0.0/params.h new/logfilegen-1.1.0/params.h --- old/logfilegen-1.0.0/params.h 2023-01-30 15:52:47.000000000 +0100 +++ new/logfilegen-1.1.0/params.h 2023-02-06 16:09:14.000000000 +0100 @@ -33,7 +33,6 @@ bool benchmark; bool stats; - void print(); }; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/logfilegen-1.0.0/templates/example-nginx-test.tp new/logfilegen-1.1.0/templates/example-nginx-test.tp --- old/logfilegen-1.0.0/templates/example-nginx-test.tp 2023-01-30 15:52:47.000000000 +0100 +++ new/logfilegen-1.1.0/templates/example-nginx-test.tp 1970-01-01 01:00:00.000000000 +0100 @@ -1,12 +0,0 @@ -$remote_addr=IP_RANDOM -$remote_user=USER_WORD|USER_NUMBER -#$time_local=%x:%X -$request=POST -$status=200|404 -$body_bytes_sent=100..10000 -$testvar=HELLO|WORLD -$time_iso8601=%Y-%m-%dT%H:%M:%SZ -$str_random01=6 -$int_random01=12 -$logstring=$time_iso8601 $testvar $remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" $str_random01 test test $int_random01 - diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/logfilegen-1.0.0/tpl.cpp new/logfilegen-1.1.0/tpl.cpp --- old/logfilegen-1.0.0/tpl.cpp 2023-01-30 15:52:47.000000000 +0100 +++ new/logfilegen-1.1.0/tpl.cpp 2023-02-06 16:09:14.000000000 +0100 @@ -14,8 +14,10 @@ #include "tpl.h" #include "utl.h" - - +//full nginx vars see at +//http://nginx.org/en/docs/varindex.html +//Apache: +//https://httpd.apache.org/docs/current/mod/mod_log_config.html void CTpl::replace_value_by_key (const string &key, const string &value) @@ -30,7 +32,6 @@ } - CTpl::~CTpl() { delete pf; @@ -44,7 +45,6 @@ CTpl::CTpl (const string &fname, const string &amode) { - pf = new CPairFile (fname, false); mode = amode; @@ -60,40 +60,23 @@ if (mode == "nginx") { vars.insert (std::make_pair ("$logstring", new CVar ("$logstring", logstrings["nginx"]))); - vars.insert (std::make_pair ("$body_bytes_sent", new CVar ("$body_bytes_sent", "1..9999"))); vars.insert (std::make_pair ("$connection_time", new CVar ("$connection_time", "0.001..60.000"))); vars.insert (std::make_pair ("$document_uri", new CVar ("$document_uri", "/|/favico.ico|/doc"))); - vars.insert (std::make_pair ("$https", new CVar ("$https", "on|"))); - - vars.insert (std::make_pair ("$http_referer", new CVar ("$http_referer", "-"))); - - - vars.insert (std::make_pair ("$http_user_agent", new CVar ("$http_user_agent", "Mozilla|Chrome|Vivaldi|Opera"))); - vars.insert (std::make_pair ("$is_args", new CVar ("$is_args", "?|"))); - - - -// vars.insert (std::make_pair ("$seconds_random", new CVar ("$seconds_random", "0.001..60.000"))); - vars.insert (std::make_pair ("$pipe", new CVar ("$pipe", "p|."))); - vars.insert (std::make_pair ("$protocol", new CVar ("$protocol", " TCP/UDP"))); vars.insert (std::make_pair ("$remote_addr", new CVar ("$remote_addr", "@ip"))); vars.insert (std::make_pair ("$remote_user", new CVar ("$remote_user", "@str:8|@int:8"))); vars.insert (std::make_pair ("$request", new CVar ("$request", "GET|POST|PUT|PATCH|DELETE"))); vars.insert (std::make_pair ("$request_completion", new CVar ("$request_completion", "ok|"))); - vars.insert (std::make_pair ("$request_id", new CVar ("$request", "@hex:16"))); vars.insert (std::make_pair ("$request_time", new CVar ("$request_time", "0.001..60.000"))); vars.insert (std::make_pair ("$server_protocol", new CVar ("$server_protocol", "HTTP/1.0|HTTP/1.1|HTTP/2.0"))); - vars.insert (std::make_pair ("$scheme", new CVar ("$scheme", "http|https"))); - vars.insert (std::make_pair ("$status", new CVar ("$status", "200|400"))); vars.insert (std::make_pair ("$time_iso8601", new CVar ("$time_iso8601", "@datetime:%Y-%m-%dT%H:%M:%SZ"))); //don't redefine vars.insert (std::make_pair ("$time_local", new CVar ("$time_local", "@datetime:%d/%b/%Y:%H:%M:%S %z"))); @@ -111,15 +94,13 @@ vars.insert (std::make_pair ("%l", new CVar ("%l", "@str:8|-"))); vars.insert (std::make_pair ("%u", new CVar ("%u", "@str:8|-"))); vars.insert (std::make_pair ("%t", new CVar ("%t", "@datetime:%d/%b/%Y:%H:%M:%S %z"))); - vars.insert (std::make_pair ("%r", new CVar ("%r", "/GET /hello.html HTTP/1.1."))); +// vars.insert (std::make_pair ("%r", new CVar ("%r", "/GET /hello.html HTTP/1.1."))); - //GET /hello.html HTTP/1.1. + vars.insert (std::make_pair ("%r", new CVar ("%r", "@meta:(@seq:/GET:/PUT) (@path:1:5:3) (@seq:HTTP/1.1:/HTTP/2.0)"))); //$request $uri $protocol vars.insert (std::make_pair ("%>s", new CVar ("%>s", "200|400"))); vars.insert (std::make_pair ("%b", new CVar ("%b", "1..9999"))); - - } @@ -163,12 +144,9 @@ i = logstring.find (variable); if (i != string::npos) // logstring = logstring.replace (i, variable.length(), it->second->get_val()); - logstring.replace (i, variable.length(), it->second->get_val()); - + logstring.replace (i, variable.length(), it->second->get_val()); } while (i != string::npos); - - } return logstring; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/logfilegen-1.0.0/tpl.h new/logfilegen-1.1.0/tpl.h --- old/logfilegen-1.0.0/tpl.h 2023-01-30 15:52:47.000000000 +0100 +++ new/logfilegen-1.1.0/tpl.h 2023-02-06 16:09:14.000000000 +0100 @@ -30,6 +30,4 @@ }; - #endif - diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/logfilegen-1.0.0/utl.cpp new/logfilegen-1.1.0/utl.cpp --- old/logfilegen-1.0.0/utl.cpp 2023-01-30 15:52:47.000000000 +0100 +++ new/logfilegen-1.1.0/utl.cpp 2023-02-06 16:09:14.000000000 +0100 @@ -2,9 +2,6 @@ * this code by Peter Semiletov is Public Domain * **********************************************************/ -#ifndef UTL_H -#define UTL_H - //#include <sys/statvfs.h> #include <sys/stat.h> @@ -167,7 +164,6 @@ } - string str_replace (string &source, const string &text_to_find, const string &replace_with) { if (source.empty()) @@ -190,7 +186,6 @@ } - string string_replace_all (const string &s, const string &from, const string &to) { string result = s; @@ -207,7 +202,7 @@ } -vector <string> split_string_to_vector (const string& s, const string& delimeter, const bool keep_empty = true) +vector <string> split_string_to_vector (const string& s, const string& delimeter, const bool keep_empty) { vector <string> result; @@ -242,7 +237,7 @@ { string result = s; - std::for_each ( + std::for_each ( result.begin(), result.end(), [](char & c) { @@ -264,7 +259,6 @@ if (st) result = strtoull (st, &end, 10); - string s = string_to_lower (val); if (s.find ("k") != string::npos) @@ -279,7 +273,6 @@ return result; } - string string_file_load (const string &fname) { std::ifstream t (fname.c_str()); @@ -315,4 +308,11 @@ } -#endif +string get_macro_name (const string &value) +{ + size_t pos = value.find_first_of (':'); + if (pos == string::npos) + pos = value.size(); + + return value.substr (0, pos); +} diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/logfilegen-1.0.0/utl.h new/logfilegen-1.1.0/utl.h --- old/logfilegen-1.0.0/utl.h 2023-01-30 15:52:47.000000000 +0100 +++ new/logfilegen-1.1.0/utl.h 2023-02-06 16:09:14.000000000 +0100 @@ -33,7 +33,7 @@ size_t string_to_file_size (const string &val); string string_file_load (const string &fname); vector <string> vector_file_load (const string &fname); - +string get_macro_name (const string &value); #endif diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/logfilegen-1.0.0/vars.cpp new/logfilegen-1.1.0/vars.cpp --- old/logfilegen-1.0.0/vars.cpp 2023-01-30 15:52:47.000000000 +0100 +++ new/logfilegen-1.1.0/vars.cpp 2023-02-06 16:09:14.000000000 +0100 @@ -1,8 +1,3 @@ -//full nginx vars see at -//http://nginx.org/en/docs/varindex.html -//Apache: -//https://httpd.apache.org/docs/current/mod/mod_log_config.html - #include <fstream> #include <iostream> #include <sstream> @@ -30,21 +25,10 @@ if (s.find ("..") != string::npos) return VT_RANGE; - return VT_SINGLE; } -string get_macro_name (const string &value) -{ - size_t pos = value.find_first_of (':'); - if (pos == string::npos) - pos = value.size(); - - return value.substr (0, pos); -} - - CVar::CVar (const string &key, const string &val) { k = key; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/logfilegen-1.0.0/vars.h new/logfilegen-1.1.0/vars.h --- old/logfilegen-1.0.0/vars.h 2023-01-30 15:52:47.000000000 +0100 +++ new/logfilegen-1.1.0/vars.h 2023-02-06 16:09:14.000000000 +0100 @@ -32,12 +32,8 @@ std::random_device rnd_dev; CMacrosPool pool; - CMacrosCache cache; - //map <string, CMacro*> macros; - - int vartype; int precision; int rnd_length; @@ -61,6 +57,4 @@ }; - - #endif
