Coder Social home page Coder Social logo

reagentx / logria-py Goto Github PK

View Code? Open in Web Editor NEW
7.0 5.0 2.0 68.03 MB

A powerful CLI tool that puts log analytics at your fingertips. Python implementation.

License: GNU General Public License v3.0

Python 99.48% Shell 0.52%
cli logging analytics tail python multiprocessing parsing regex grep

logria-py's Introduction

Logria Logo

Logria Python Proof of Concept

A powerful CLI tool that puts log analytics at your fingertips. This is the Python Proof of Concept repository; the main version is written in Rust.

tl;dr

  • Live filtering of data from other processes, replacing grep
  • Use shell commands or files as input, save sessions and come back later
  • Replace regex/filter without killing the process or losing the stream's history
  • Parse logs using user-defined rules, apply analytics methods on top
  • Pure Python, fully type hinted, zero dependencies

Installation

There are several options to install this app.

Normal Usage

pip install logria

Development

See Advanced Installation.

Usage

There are a few main ways to invoke Logria:

  • Directly:
    • logria
    • Opens to the setup screen
  • With args:
    • logria -e 'tail -f log.txt'
    • Opens a pipe to tail -f log.txt and skips setup
    • logria -h will show the help page with all possible options

For more details, see Sample Usage Session.

Key Commands

Key Command
: command mode
/ regex search
h if regex active, toggle highlighting of matches
i toggle insert mode (default off)
s swap reading stdin and stdout
p activate parser
a toggle analytics mode when parser is active
z deactivate parser
scroll buffer up one line
scroll buffer down one line
skip and stick to end of buffer
skip and stick to beginning of buffer

Features

Here are some of the ways you can leverage Logria:

Live stream of log data

logria

Interactive, live, editable grep

regex

Live log message parsing

parser

Live analytics/statistics tracking

analytics

User-defined saved sessions

See session docs.

User-defined saved log parsing methods

See patterns docs.

logria-py's People

Contributors

reagentx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

logria-py's Issues

Improve unit test coverage

Name                                    Stmts   Miss  Cover   Missing
---------------------------------------------------------------------
logria/__init__.py                          2      0   100%
logria/commands/__init__.py                 0      0   100%
logria/commands/command.py                 37     31    16%   18-24, 32-63
logria/commands/config.py                 176    142    19%   51-82, 89-114, 122-148, 155-224, 231-244
logria/commands/edit.py                     5      4    20%   13-17
logria/commands/parser.py                 116    106     9%   20-42, 50-146, 153-155, 162-171, 178
logria/commands/regex.py                   52     44    15%   19-31, 38-60, 68-83, 90-96
logria/commands/scroll.py                  33      2    94%   31, 46
logria/commands/window.py                  11      7    36%   15-22, 29
logria/communication/__init__.py            0      0   100%
logria/communication/input_handler.py      60     35    42%   36, 42, 69-99, 106-110, 123-134
logria/communication/input_history.py      79      4    95%   33, 39, 48-49
logria/communication/render.py             35      0   100%
logria/communication/setup.py              74     63    15%   26-33, 41-118
logria/communication/shell_output.py      192    117    39%   104-122, 134-171, 177-181, 187-189, 197-201, 207-212, 218-236, 242-243, 249-252, 267, 271, 278-356
logria/interface/__init__.py                0      0   100%
logria/interface/color_handler.py          89     54    39%   68-75, 79-87, 101-124, 128-139, 152-166
logria/interface/textbox.py               159    144     9%   18-25, 54-62, 68-70, 77-87, 93-115, 121-198, 204-220, 226, 235-246
logria/logger/__init__.py                   0      0   100%
logria/logger/default_logger.py            10      0   100%
logria/logger/parser.py                   154      2    99%   42, 104
logria/logger/processor.py                 20      0   100%
logria/utilities/__init__.py                0      0   100%
logria/utilities/command_parser.py         51      0   100%
logria/utilities/constants.py              30      0   100%
logria/utilities/fs.py                      7      0   100%
logria/utilities/keystrokes.py             10      0   100%
logria/utilities/regex_generator.py        11      0   100%
logria/utilities/session.py                65      2    97%   53, 57
tests/__init__.py                           0      0   100%
tests/test_app_launch.py                   23      0   100%
tests/test_color_handler.py                12      0   100%
tests/test_command_parser.py               56      0   100%
tests/test_constants.py                    11      0   100%
tests/test_fs.py                           17      0   100%
tests/test_history_tape.py                134      0   100%
tests/test_input_handler.py                20      0   100%
tests/test_keystrokes.py                    8      0   100%
tests/test_parser.py                      194      0   100%
tests/test_processors.py                  194      0   100%
tests/test_regex_generator.py              19      0   100%
tests/test_render_position.py             371      0   100%
tests/test_resolve_delete.py               33      0   100%
tests/test_session.py                      82      0   100%
---------------------------------------------------------------------
TOTAL                                    2652    757    71%

Smart poll rate

We can automatically reduce the poll rate while we are just listening and increase it when asking for input to reduce CPU impact.

Crash when a PATH folder has a ~ in its env var

#If a folder on your PATH is defined with a ~ Logria will crash because it interprets the tilde as a folder name and not the user’s home directory. This can be rectified by calling resolve_home_dir as we iterate.

Crash with -n cli arg

Traceback (most recent call last):
  File "/Users/chris/.pyenv/versions/3.8.4/bin/logria", line 8, in <module>
    sys.exit(main())
  File "/Users/chris/.pyenv/versions/3.8.4/lib/python3.8/site-packages/logria/__main__.py", line 46, in main
    app = Logria(stream, history_tape_cache=args.no_cache, )
AttributeError: 'list' object has no attribute 'no_cache'

Not compatible with Powershell/Windows CMD

PS C:\Users\Development\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\Scripts> .\logria.exe                                                                                       Namespace(e=None)
Traceback (most recent call last):
  File "C:\Users\Development\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\Scripts\logria-script.py", line 11, in <module>
    load_entry_point('logria', 'console_scripts', 'logria')()
  File "c:\users\development\documents\code\logria\logria\__main__.py", line 31, in main
    app.start()
  File "c:\users\development\documents\code\logria\logria\communication\shell_output.py", line 246, in start
    curses.wrapper(self.main)
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.496.0_x64__qbz5n2kfra8p0\lib\curses\__init__.py", line 105, in wrapper
    return func(stdscr, *args, **kwds)
  File "c:\users\development\documents\code\logria\logria\communication\shell_output.py", line 267, in main
    self.command_line = curses.newwin(1, width, height - 2, 1)
_curses.error: curses function returned NULL

:config crash

  File "/Users/h14384/.pyenv/versions/3.8.6/lib/python3.8/site-packages/logria/commands/config.py", line 233, in config_mode
    logria.refresh()
AttributeError: 'Logria' object has no attribute 'refresh'

App support for pruning sessions and parsers

Right now, the only way to remove sessions or parsers is to cd to them and manually remove them. We should add this to config mode so we can remove sessions or parsers that we do not want.

ValueError: embedded null character crash in addstr

Traceback (most recent call last):
  File "/Users/chris/.pyenv/versions/3.8.3/bin/logria", line 8, in <module>
    sys.exit(main())
  File "/Users/chris/.pyenv/versions/3.8.3/lib/python3.8/site-packages/logria/__main__.py", line 47, in main
    app.start()
  File "/Users/chris/.pyenv/versions/3.8.3/lib/python3.8/site-packages/logria/communication/shell_output.py", line 248, in start
    curses.wrapper(self.main)
  File "/Users/chris/.pyenv/versions/3.8.3/lib/python3.8/curses/__init__.py", line 105, in wrapper
    return func(stdscr, *args, **kwds)
  File "/Users/chris/.pyenv/versions/3.8.3/lib/python3.8/site-packages/logria/communication/shell_output.py", line 344, in main
    self.render_text_in_output()
  File "/Users/chris/.pyenv/versions/3.8.3/lib/python3.8/site-packages/logria/communication/shell_output.py", line 165, in render_text_in_output
    color_handler.addstr(self.outwin, current_row, 0, item.rstrip())
  File "/Users/chris/.pyenv/versions/3.8.3/lib/python3.8/site-packages/logria/interface/color_handler.py", line 152, in addstr
    return _inner_addstr(window, string, y_coord, x_coord)
  File "/Users/chris/.pyenv/versions/3.8.3/lib/python3.8/site-packages/logria/interface/color_handler.py", line 123, in _inner_addstr
    _add_line(y_coord, x_coord, window, line)
  File "/Users/chris/.pyenv/versions/3.8.3/lib/python3.8/site-packages/logria/interface/color_handler.py", line 94, in _add_line
    window.addstr(y_coord, x_coord, color_split[0], curses.color_pair(default_color_pair))
ValueError: embedded null character

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.