Install and Verify
The first thing to do is install it, which is done as simply as:
$ gem install pantheios-ruby
(You may need/prefer to download the latest gem from rubygems and install from a local gem file. You may need the right privileges, so could require sudo.)
You can then verify the installation with the one-line:
$ ruby -e 'require "pantheios" ; puts Pantheios::VERSION;'
and should see output such as:
0.22.0
Basic Script
Next, we'll create a minimally-featured script that does some logging. Using vim - I mean, what else is there?! - create a script hello_pantheios.rb with the following contents:
#! /usr/bin/env ruby
require "pantheios"
include ::Pantheios
log(:notice, "Hello, World of Logs!")
and then execute as follows:
$ ruby hello_pantheios.rb
you'll see output such as:
[hello_pantheios, 70345600268220, 2020-06-13 10:09:21.867107, Notice]: Hello, World of Logs!
Coming up:
In the next post we'll create a first version of a file-system search program with which we will illustrate a whole raft of Pantheios.Ruby features, including (but not limited to):- using different severity levels and ascribing meaning to those levels;
- filtering based on severity levels, including using front-ends to make decisions about which severity levels will be output;
- choosing back-ends, i.e. where logged output goes, including:
- logging to the console;
- logging to the console with severity level-related colours;
- files;
- syslog;
- Ruby's standard logger;
- log4r;
- ... and so on;
- naming threads;
- customising the prefix - the bit above that contains "[hello_pantheios, 70345600268220, 2020-06-13 10:09:21.867107, Notice]: ";
- ... and many more things I can't think of right now. That's why we're going to write an actually useful program to exercise it.
No comments:
Post a Comment