logger :: FileLogger
var log_file = "my_file.log"
var logger = new FileLogger(warn_level, log_file, append = false)
logger.error("An error")
logger.info("Some info")
logger.close
assert log_file.to_path.read_all == "An error\n"
logger = new FileLogger(warn_level, log_file, append = true)
logger.error("Another error")
logger.close
assert log_file.to_path.read_all == "An error\nAnother error\n"
log_file.to_path.delete
logger :: FileLogger :: append=
Append messages tofile
logger :: FileLogger :: defaultinit
logger $ FileLogger :: SELF
Type of this instance, automatically specialized in every classlogger $ FileLogger :: init
logger :: FileLogger :: append=
Append messages tofile
core :: Object :: class_factory
Implementation used byget_class
to create the specific class.
logger :: Logger :: default_formatter
Formatter used to format messages before outputting themlogger :: Logger :: default_formatter=
Formatter used to format messages before outputting themcore :: Object :: defaultinit
logger :: FileLogger :: defaultinit
logger :: Logger :: defaultinit
core :: Object :: is_same_instance
Return true ifself
and other
are the same instance (i.e. same identity).
core :: Object :: is_same_serialized
Isself
the same as other
in a serialization context?
core :: Object :: is_same_type
Return true ifself
and other
have the same dynamic type.
core :: Object :: output_class_name
Display class name on stdout (debug only).
# Log messages to a file
#
# ~~~
# var log_file = "my_file.log"
# var logger = new FileLogger(warn_level, log_file, append = false)
# logger.error("An error")
# logger.info("Some info")
# logger.close
# assert log_file.to_path.read_all == "An error\n"
#
# logger = new FileLogger(warn_level, log_file, append = true)
# logger.error("Another error")
# logger.close
# assert log_file.to_path.read_all == "An error\nAnother error\n"
#
# log_file.to_path.delete
# ~~~
class FileLogger
super Logger
autoinit level, file, append, default_formatter
redef type OUT: FileWriter
# File where messages will be written
var file: String
# Append messages to `file`
#
# If `append` is `false`, the `file` will be overwritten.
var append: Bool = true is optional
init do
var old = null
if append then
old = file.to_path.read_all
end
out = new FileWriter.open(file)
out.set_buffering_mode(0, buffer_mode_line)
if old != null then
out.write(old)
end
end
# Close the logger and its `file`
fun close do out.close
end
lib/logger/logger.nit:264,1--309,3