LogFile¶
-
class
utilipy.
LogFile
(filename: Optional[str] = None, verbose: int = 0, sec_div: str = '-', header: Union[str, None, bool] = None, show_header: bool = True, mode: str = 'w', buffering: int = - 1, encoding: None = None, errors: None = None, newline: None = None, closefd: bool = True, opener: None = None)[source]¶ Bases:
utilipy.utils.logging.LogPrint
Class for basic logger that can both print and record to a file.
this class uses
open
, not a more extensive logger, likelogging
The arguments
mode
toopener
are all foropen
their descriptions are in https://docs.python.org/3/library/functions.html#open- Parameters
- filenamestr, optional
the file name / path at which to save this log If no filename, makes a
LogPrint
instead- verboseint, optional
the verbosity level to use in
.report
- modestr, optional
recommend either ‘w’ or ‘a’
- sec_divstr, optional
the section divider used in
newsection
- headerNone or str, optional
the header for the file None goes to filename
- show_headerbool, optional
whether to print the header
Notes
- mode options
‘r’ open for reading
‘w’ open for writing, truncating the file first
‘x’ open for exclusive creation, failing if the file already exists
‘a’ open for writing, appending to the end of the file if it exists
‘b’ binary mode
‘t’ text mode
NOT ALLOWED ‘+’ open a disk file for updating (reading and writing)
LogFile.
set the filename and make the file
Methods Summary
close
()Close the file.
open
(filename[, verbose, sec_div, header, …])Make basic logger that can both print and record to a file.
open_to_read
(filename[, buffering, …])Make basic logger that can both print and record to a file.
open_to_write
(filename[, verbose, sec_div, …])Make basic logger that can both print and record to a file.
record
(*text[, start, end, startsection, …])Write, but doesn’t print as well as write to file.
report
(*msgs[, verbose, print, write, start_at])a report function whose message is determined by the
verbose
.write
(*text[, start, sep, end, …])Write string to stream and print it to output.
Methods Documentation
-
classmethod
open
(filename: str, verbose: int = 0, sec_div: str = '-', header: Optional[str] = None, show_header: bool = True, mode: str = 'w', buffering: int = - 1, encoding: None = None, errors: None = None, newline: None = None, closefd: bool = True, opener: None = None) → Any[source]¶ Make basic logger that can both print and record to a file.
this class uses
open
, not a more extensive logger, likelogging
The arguments
mode
toopener
are all foropen
their descriptions are in https://docs.python.org/3/library/functions.html#open- Parameters
- filename: str
the file name / path at which to save this log
- mode: str
recommend either ‘w’ or ‘a’
- sec_div: str
the section divider used in
newsection
- headerNone or str
the header for the file None -> filename
Notes
- mode options
‘r’ open for reading
‘w’ open for writing, truncating the file first
‘x’ open for exclusive creation, failing if file already exists
‘a’ open for writing, appending to the end of file if it exists
‘b’ binary mode
‘t’ text mode
‘+’ open a disk file for updating (reading and writing)
-
classmethod
open_to_read
(filename: str, buffering: int = - 1, encoding: None = None, errors: None = None, newline: None = None, closefd: bool = True, opener: None = None) → Any[source]¶ Make basic logger that can both print and record to a file.
this class uses
open
, not a more extensive logger, likelogging
The arguments
buffering
toopener
are all foropen
their descriptions are in https://docs.python.org/3/library/functions.html#open- Parameters
- filename: str
the file name / path at which to save this log
-
classmethod
open_to_write
(filename: str, verbose: int = 0, sec_div: str = '-', header: Optional[str] = None, show_header: bool = True, mode: int = 'w', buffering: int = - 1, encoding: None = None, errors: None = None, newline: None = None, closefd: bool = True, opener: None = None) → Any[source]¶ Make basic logger that can both print and record to a file.
this class uses
open
, not a more extensive logger, likelogging
The arguments
mode
toopener
are all foropen
their descriptions are in https://docs.python.org/3/library/functions.html#open- Parameters
- filename: str
the file name / path at which to save this log
- mode: str
recommend either ‘w’ or ‘a’ cannot be ‘r’
- sec_div: str
the section divider used in
newsection
- headerNone or str, optional
the header for the file None -> filename
Notes
- mode options
‘w’ open for writing, truncating the file first
‘x’ open for exclusive creation, failing if file already exists
‘a’ open for writing, appending to the end of file if it exists
‘b’ binary mode
‘t’ text mode
‘+’ open a disk file for updating (reading and writing)
-
record
(*text: str, start: str = '', end: str = '\n', startsection: bool = False, endsection: bool = False) → Any[source]¶ Write, but doesn’t print as well as write to file.
-
report
(*msgs: str, verbose: Optional[int] = None, print: bool = True, write: bool = True, start_at: int = 1, **kw) → Any[source]¶ a report function whose message is determined by the
verbose
.- Parameters
- msgsstr(s)
the verbosity-ordered messages blank messages can be <None>, not only ‘’
- verboseint, optional
which message to record None (default) uses self.verbose (default = 0, unless specified)
- printbool
whether to print, or just record
- writebool
whether to write to logger file
- start_atint
what level of verbosity is the first
msgs
ex: verbort(‘test’, start_at=3) means ‘test’ is at verbose=3- kw: kwargs for self.write or self.print
-
write
(*text: str, start: str = '', sep: str = ' ', end: str = '\n', startsection: bool = False, endsection: bool = False, print: bool = True) → Any[source]¶ Write string to stream and print it to output.
- Parameters
- text: str
the text to write & print
- start: str
start to print
- sep: str
the separater for print
- end: str
the end for print
- startsection: bool
whether to start a new section before writing
- endsection: bool