Class: PrettyLogs::Parsers::PlainTextParser
- Inherits:
-
Object
- Object
- PrettyLogs::Parsers::PlainTextParser
- Defined in:
- lib/pretty_logs/parsers/plain_text_parser.rb
Constant Summary collapse
- LOG_PATTERN =
Matches standard log format: TIMESTAMP [LEVEL] message
/^(\d{4}-\d{2}-\d{2}[T\s]\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})?)\s*\[(\w+)\]\s+(.*)$/
Class Method Summary collapse
Class Method Details
.parse(line) ⇒ Object
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/pretty_logs/parsers/plain_text_parser.rb', line 9 def self.parse(line) match = line.match(LOG_PATTERN) return nil unless match { timestamp: match[1], level: match[2], message: match[3] } end |
.parse?(line) ⇒ Boolean
20 21 22 |
# File 'lib/pretty_logs/parsers/plain_text_parser.rb', line 20 def self.parse?(line) !parse(line).nil? end |