This instructable describes the ease of making a python based Logger on Linux based systems. I am doing this on a Raspberry Pi, but it will work on all Linux distros. You will need Superuser Access. In simpler terms, you need to be an admin.

This logger app will be able to save simple lines of text to a .txt file and spit them out when desired.

What You Can Do: By typing "log" in terminal, you will be prompted with a field to enter your log. And on typing "viewlog" in terminal, you will see all the logs you have entered along with their time of entry

With no more delay, lets get started.

Step 1: Login to Superuser

First, you will have to login as superuser. Go to terminal and type:

sudo -s

This will allow you to make admin changes without typing sudo every time. You can log out of this Super Saiyan form by typing:


Step 2: Make a Directory Name "/log"

Now you have to make a directory named "/log". Note that this directory has been made in root just for convenience. You can make it anywhere, but if you do, remember to change the file paths through the code as well. You can make the directory by typing in:

mkdir /log/

Step 3: Make the Python Code

Now you have to make the code for the Logger. Create the source file by typing in:

sudo nano /log/Logger.py

You will open up a nano editor window. Type in the following:

import datetime

file = "/log/Log.txt"
iput = str(raw_input("\fEnter Log Here : "))
inFile = open(file,'r')
time = datetime.datetime.now().isoformat()
buffer = inFile.read()+"\n"+time+"\n\t"+iput+"\n___________________________________\n"
outFile = open(file, 'wt')
print("\nLog updated sucessfully!!\n")

Then control+x to exit, then y to save and then press enter.

Step 4: Make the Log.txt

Now you have to create the log file. You can do so typing in:

nano /log/Log.txt

Then go ahead and type in something like "LOG" for the heading.

Step 5: Make the Alias

Now you have to log out of Superuser by typing:


Then type in:

alias log="sudo python /log/Logger.py"


alias viewlog="nano /log/Log.txt"

Step 6: Test Log Command

Type in:


in the terminal and you should be prompted to enter a log.

Step 7: Test the Viewlog Command

Type in:


in the terminal and you should be prompted a nano open with the "/log/Log.txt" file open. You should also see your log.

<p>I'm not familiar with this. What would it be used for?</p>
<p>Well, you see: some people are using their Linux boxes only iva terminal for long periods of time. And sometimes it may become necessary to log something. Lets say:</p><p>1) A command you may want to remember, </p><p>2) You just want to log some data that you can later convert to a blog (not part of project)</p><p>3) Quickly jot-down an idea for some improvement for the system, etc</p><p>This project seeks to create something like a productivity application. However, you may take this project as a means of learning coding.</p><p>In the end, I would like to thank you for noticing my existance</p>

About This Instructable



More by Aditya N G:Terminal Logger 
Add instructable to: