Skip to content

'tail -f' file server written in asynchronous Python using WebSockets

Notifications You must be signed in to change notification settings

kuralabs/logserver

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Log Server

Small example of how to implement a "tail -f" file server in Python using asyncio. Streaming of the file contents to the client is done using WebSockets.

In order to monitor file changes Linux's inotify (using aionotify) is used in conjunction with aiofile to read files asynchronously (using POSIX's aio.h).

Thus, this example can only run in Linux using modern kernels.

Usage

Server

Start the server with:

$ cd server
$ virtualenv venv
$ source venv/bin/activate
$ pip3 install -r requirements.txt
$ ./server.py

This will start a server that listen on port 9292. There is one endpoint:

/follow/{filename}

The server will look for filename in the current working directory and start streaming its content.

There is a small tool noiser.py that will make sure to make noise on a file. So, in another terminal, you may start making noise in a file with:

$ ./noiser.py afile.log

Thus /follow/afile.log will allow to follow the writes in that file.

Clients

There is an assorted collection of clients:

  • HTML5 / Javascript.
  • React.
  • Python 3 synchronous.
  • Python 3 asynchronous.

Feel free to explore the code in the clients/ directory.

License

Copyright (C) 2019 KuraLabs S.R.L

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.

About

'tail -f' file server written in asynchronous Python using WebSockets

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published