logeasy 0.0.4 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/lib/logeasy.rb CHANGED
@@ -5,33 +5,6 @@
5
5
 
6
6
  # Easy logger module.
7
7
  # This module is not thread safe.
8
- #
9
- # Usage:
10
- #
11
- # To create a new logger:
12
- # LogEasy::Logger.get_logger(<logger_name>)
13
- # logger_name - this should be a '.' separated or '::' separated hierarchy of loggers.
14
- # eg. LogEasy::Logger.get_logger("ModuleName::SubModule::ClassName")
15
- #
16
- # To change the level of a logger.
17
- # LogEasy::Logger.get_logger(<logger_name>).change_min_level(<new_level>) # Recursively changes this logger and all child loggers.
18
- # LogEasy::Logger.get_logger(<logger_name>).min_level = <new_level> # Only change this logger's level.
19
- # logger_name - the logger name.
20
- # new_level - the new level to set (instance of LogEasy::Level).
21
- # eg. LogEasy::Logger.get_logger("ModuleName::SubModule::ClassName").change_min_level(LogEasy::Level::INFO)
22
- #
23
- # To add an appender to a logger.
24
- # LogEasy::Logger.get_logger(<logger_name>).add_appender(<appender>)
25
- # logger_name - the logger name.
26
- # appender - the appender to add (instance of LogEasy::Appender).
27
- # eg. LogEasy::Logger.get_logger("ModuleName::SubModule::ClassName").add_appender(LogEasy::ConsoleAppender.new)
28
- #
29
- # By default all sub-loggers will also use this appender. A logger can be told not to use a parent's appender using the
30
- # 'use_parent_logger' flag. So by adding an appender to the root logger, logs sent to any logger will, by default,
31
- # be logged by the root logger's appender(s) also.
32
- #
33
- # Right now the only way to configure the loggers is using code. Look at example/example.rb for how to do that.
34
- #
35
8
  module LogEasy
36
9
 
37
10
  require "logeasy/logger"
@@ -92,21 +92,28 @@ module LogEasy
92
92
  # File appenders write messages to a file.
93
93
  class FileAppender < Appender
94
94
 
95
+ # Closes this appender. This will also remove the appender from its logger.
96
+ def close
97
+ file.close
98
+ logger.remove_appender(self) if not logger.nil?
99
+ end
100
+
95
101
  private
96
102
 
97
103
  attr_reader :file
104
+ attr_reader :file_path
98
105
 
99
106
  # Creates a new file appender.
100
107
  # If the specified file already exists, it is overwritten.
101
108
  def initialize(file_path)
102
109
  super()
103
- @file = File.open(file_path, "w")
110
+ @file_path = file_path
111
+ create_file
104
112
  end
105
113
 
106
- # Closes this appender. This will also remove the appender from its logger.
107
- def close
108
- file.close
109
- logger.remove_appender(self) if not logger.nil?
114
+ # Default create file will overwrite existing files.
115
+ def create_file
116
+ @file = File.open(file_path, "w")
110
117
  end
111
118
 
112
119
  # Writes the message to the file.
@@ -117,4 +124,14 @@ module LogEasy
117
124
 
118
125
  end
119
126
 
127
+ # A file appender that writes to the end of the file if it exists.
128
+ class ConcatFileAppender < FileAppender
129
+
130
+ # Overrides default create file. This will use an existing file.
131
+ def create_file
132
+ @file = File.open(file_path, "a")
133
+ end
134
+
135
+ end
136
+
120
137
  end
@@ -10,6 +10,32 @@ require "logeasy/appender"
10
10
  module LogEasy
11
11
 
12
12
  # The logger class. Use the 'get_logger' method to create and use loggers.
13
+ #
14
+ # Usage:
15
+ #
16
+ # To create a new logger:
17
+ # LogEasy::Logger.get_logger(<logger_name>)
18
+ # logger_name - this should be a '.' separated or '::' separated hierarchy of loggers.
19
+ # eg. LogEasy::Logger.get_logger("ModuleName::SubModule::ClassName")
20
+ #
21
+ # To change the level of a logger.
22
+ # LogEasy::Logger.get_logger(<logger_name>).change_min_level(<new_level>) # Recursively changes this logger and all child loggers.
23
+ # LogEasy::Logger.get_logger(<logger_name>).min_level = <new_level> # Only change this logger's level.
24
+ # logger_name - the logger name.
25
+ # new_level - the new level to set (instance of LogEasy::Level).
26
+ # eg. LogEasy::Logger.get_logger("ModuleName::SubModule::ClassName").change_min_level(LogEasy::Level::INFO)
27
+ #
28
+ # To add an appender to a logger.
29
+ # LogEasy::Logger.get_logger(<logger_name>).add_appender(<appender>)
30
+ # logger_name - the logger name.
31
+ # appender - the appender to add (instance of LogEasy::Appender).
32
+ # eg. LogEasy::Logger.get_logger("ModuleName::SubModule::ClassName").add_appender(LogEasy::ConsoleAppender.new)
33
+ #
34
+ # By default all sub-loggers will also use this appender. A logger can be told not to use a parent's appender using the
35
+ # 'use_parent_logger' flag. So by adding an appender to the root logger, logs sent to any logger will, by default,
36
+ # be logged by the root logger's appender(s) also.
37
+ #
38
+ # Right now the only way to configure the loggers is using code. Look at example/example.rb for how to do that.
13
39
  class Logger
14
40
 
15
41
  # Get the logger identified by the specified name. If a logger does not exist, a new one is created and returned.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logeasy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-02-19 00:00:00.000000000 +05:30
12
+ date: 2011-02-22 00:00:00.000000000 +05:30
13
13
  default_executable:
14
14
  dependencies: []
15
15
  description: Hierarchical logger for Ruby. The loggers are arranged in a tree. Output