File: fileroll.rb

package info (click to toggle)
ruby-log4r 1.1.10-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 648 kB
  • sloc: ruby: 2,744; xml: 96; makefile: 5
file content (40 lines) | stat: -rw-r--r-- 928 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# How to use RollingFileOutputter

$: << "../lib"
require 'log4r'
include Log4r

puts "this will take a while"

# example of log file being split by time constraint 'maxtime'
config = {
  "filename" => "logs/TestTime.log",
  "maxtime" => 10,
  "trunc" => true
}
timeLog = Logger.new 'WbExplorer'
timeLog.outputters = RollingFileOutputter.new("WbExplorer", config)
timeLog.level = DEBUG

# log something once a second for 100 seconds
100.times { |t|
  timeLog.info "blah #{t}"
  sleep(1.0)
}

# example of log file being split by space constraint 'maxsize'
config = {
  "filename" => "logs/TestSize.log",
  "maxsize" => 16000,
  "trunc" => true
}
sizeLog = Logger.new 'WbExplorer'
sizeLog.outputters = RollingFileOutputter.new("WbExplorer", config)
sizeLog.level = DEBUG

# log a large number of times
100000.times { |t|
  sizeLog.info "blah #{t}"
}

puts "done! check the two sets of log files in logs/ (TestTime and TestSize)"