Class: Simplelog

Inherits:
Object
  • Object
show all
Defined in:
lib/simplelog.rb

Overview

All puts statements are logged to file and shown on screen.

To use:

require ‘simplelog’

Constant Summary collapse

@@dir =
"."
@@name =
"LOG_"
@@logtext =
""

Class Method Summary collapse

Class Method Details

.clearObject

Allows you to clear your log if you so wish



58
59
60
# File 'lib/simplelog.rb', line 58

def Simplelog.clear
  @@logtext = ""
end

.dirObject



44
45
46
# File 'lib/simplelog.rb', line 44

def Simplelog.dir
  @@dir
end

.dir=(dir) ⇒ Object

Where will you save your log? Defaults to “.”



49
50
51
# File 'lib/simplelog.rb', line 49

def Simplelog.dir=(dir)
  @@dir = dir.sub(/\\*$/, "")
end

.filenameObject

Directory and filename. Subsequent underscores are removed.



68
69
70
# File 'lib/simplelog.rb', line 68

def Simplelog.filename
  "#@@dir\\#{@@name}_#{Date.today.to_s}.txt".sub("__", "_")
end

.logtextObject



53
54
55
# File 'lib/simplelog.rb', line 53

def Simplelog.logtext
  @@logtext
end

.nameObject



35
36
37
# File 'lib/simplelog.rb', line 35

def Simplelog.name
  @@name
end

.name=(name) ⇒ Object

The logs name defaults to LOG_. This can be redefined at wish.



40
41
42
# File 'lib/simplelog.rb', line 40

def Simplelog.name=(name)
  @@name = name  
end

.puts(text) ⇒ Object



62
63
64
65
# File 'lib/simplelog.rb', line 62

def Simplelog.puts(text)
  old_puts text
  @@logtext << text << "\n"
end

.saveObject



72
73
74
75
76
77
78
79
# File 'lib/simplelog.rb', line 72

def Simplelog.save
  if !@@logtext.empty?
    File.makedirs(@@dir) if !File.directory?(@@dir)
    File.open(filename, "w") do |f|
      f.puts @@logtext
    end
  end
end