All Projects β†’ icza β†’ backscanner

icza / backscanner

Licence: Apache-2.0 License
A scanner similar to bufio.Scanner, but it reads and returns lines in reverse order, starting at a given position and going backward.

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to backscanner

scanbot-sdk-example-ionic
Scanbot scanner SDK example app for Ionic with Cordova.
Stars: ✭ 24 (-29.41%)
Mutual labels:  scanner
doom-console-log
πŸ•ΉοΈ DOOM rendered via console.log() in a web browser.
Stars: ✭ 19 (-44.12%)
Mutual labels:  log
omrmarkengine
This project is designed to allow easy creation of OMR (Optical Mark Recognition) templates and provides a bulk scanner which can be used for processing large amounts of images from a tray fed scanner.
Stars: ✭ 49 (+44.12%)
Mutual labels:  scanner
composition-logger
The most optimal way to visualize/debug functional compositions πŸ”
Stars: ✭ 15 (-55.88%)
Mutual labels:  log
NSE-scripts
NSE scripts to detect CVE-2020-1350 SIGRED and CVE-2020-0796 SMBGHOST, CVE-2021-21972, proxyshell, CVE-2021-34473
Stars: ✭ 105 (+208.82%)
Mutual labels:  scanner
Log4j-RCE-Scanner
Remote command execution vulnerability scanner for Log4j.
Stars: ✭ 200 (+488.24%)
Mutual labels:  scanner
nesca
The legendary netstalking NEtwork SCAnner
Stars: ✭ 80 (+135.29%)
Mutual labels:  scanner
jog
Command line tool to view structured(JSON) log like 'tail -f', with filtering by log level and time range
Stars: ✭ 16 (-52.94%)
Mutual labels:  log
php-invert-color
Invert a given color.
Stars: ✭ 13 (-61.76%)
Mutual labels:  reverse
Serilog.Sinks.MicrosoftTeams.Alternative
Serilog.Sinks.MicrosoftTeams.Alternative is a library to save logging information from Serilog to Microsoft Teams.
Stars: ✭ 21 (-38.24%)
Mutual labels:  log
cf-check
CloudFlare Checker written in Go
Stars: ✭ 147 (+332.35%)
Mutual labels:  scanner
garden.zbarcam
Migrated to https://github.com/kivy-garden/zbarcam
Stars: ✭ 49 (+44.12%)
Mutual labels:  scanner
Postfix-Deliverability-Analytics
[DEPRECATED] A tool that goes throu Posftix logs and builds a statistics of bounces (non-delivered messages). Statistics are provided by REST API to the client.
Stars: ✭ 21 (-38.24%)
Mutual labels:  log
log4shelldetect
Rapidly scan filesystems for Java programs potentially vulnerable to Log4Shell (CVE-2021-44228) or "that Log4j JNDI exploit" by inspecting the class paths inside files
Stars: ✭ 40 (+17.65%)
Mutual labels:  scanner
mondoo
πŸ•΅οΈβ€β™€οΈ Mondoo Cloud-Native Security & Vulnerability Risk Management
Stars: ✭ 60 (+76.47%)
Mutual labels:  scanner
analog-ce
Analog CE
Stars: ✭ 14 (-58.82%)
Mutual labels:  log
TIGER
implement a full compiler based on c++ 11
Stars: ✭ 17 (-50%)
Mutual labels:  scanner
alveare
🐝 Multi-client, multi-threaded reverse shell handler written in Node.js
Stars: ✭ 68 (+100%)
Mutual labels:  reverse
ReversePowerShell
Functions that can be used to gain Reverse Shells with PowerShell
Stars: ✭ 48 (+41.18%)
Mutual labels:  reverse
ErRabbit
Remote logging console server using Log4j. Visual exception stackTrace log view.
Stars: ✭ 48 (+41.18%)
Mutual labels:  log

backscanner

Build Status GoDoc Go Report Card codecov

Ever needed or wondered how to efficiently search for something in a log file, but starting at the end and going backward? Here's your solution.

Package backscanner provides a scanner similar to bufio.Scanner, but it reads and returns lines in reverse order, starting at a given position (which may be the end of the input) and going backward.

This library only uses the standard library, but the test uses an external package. To install this library (along with the test dependency), simply run:

go get -t github.com/icza/backscanner

Advancing and accessing lines of the input is done by calling Scanner.Line(), which returns the next line (previous in the source) as a string.

For maximum efficiency there is Scanner.LineBytes(). It returns the next line as a byte slice, which shares its backing array with the internal buffer of Scanner. This is because no copy is made from the line data; but this also means you can only inspect or search in the slice before calling Line() or LineBytes() again, as the content of the internal buffer–and thus slices returned by LineBytes()–may be overwritten. If you need to retain the line data, make a copy of it or use Line().

Example using it:

input := "Line1\nLine2\nLine3"
scanner := backscanner.New(strings.NewReader(input), len(input))
for {
	line, pos, err := scanner.Line()
	if err != nil {
		fmt.Println("Error:", err)
		break
	}
	fmt.Printf("Line position: %2d, line: %q\n", pos, line)
}

Output:

Line position: 12, line: "Line3"
Line position:  6, line: "Line2"
Line position:  0, line: "Line1"
Error: EOF

Using it to efficiently scan a file, finding last occurrence of a string ("error"):

f, err := os.Open("mylog.txt")
if err != nil {
	panic(err)
}
fi, err := f.Stat()
if err != nil {
	panic(err)
}
defer f.Close()

scanner := backscanner.New(f, int(fi.Size()))
what := []byte("error")
for {
	line, pos, err := scanner.LineBytes()
	if err != nil {
		if err == io.EOF {
			fmt.Printf("%q is not found in file.\n", what)
		} else {
			fmt.Println("Error:", err)
		}
		break
	}
	if bytes.Contains(line, what) {
		fmt.Printf("Found %q at line position: %d, line: %q\n", what, pos, line)
		break
	}
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].