Download the PHP package sohelaman/hello-log without Composer
On this page you can find all versions of the php package sohelaman/hello-log. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package hello-log
HelloLog
Hello World kind of logger for PHP
Features
- Logs data in file or returns data for printing/storing.
- Additional information like timestamp, data type, serial number is added to log.
- Simple browser friendly formatting.
- Supports major data types, arrays, objects.
- Supports output in JSON format.
- Built in counter.
- Support for changing file name any time while logging.
- Time based file name suffix can be used to segregate log files.
Basic Usage
Grab the package using Composer
Then use it in your PHP script
Documentation
Constructor
- Default constructor will use /tmp directory and a file called hellolog.log.
-
Note that in many systems, apache users like http or www-data create subdirectories under /tmp directory and then create files.
-
Instantiate with path and file segmentation configurations
-
Third constructor parameter is the overwrite flag. If it's true, then the file will be overwritten on each log.
- NOTE that, once overwrite flag is turned on, file will be overwritten EACH time you put anyting into log file. So, previous content will be gone from that file. Overwrite flag can be turned on or off using overwrite() method. If not explicitly specified, overwrite flag is truned off by default.
File Segmentation
- Log file segmentation puts a suffix in log file name based on time.
- For example, 'DAY' will add a suffix for a day, such as 2016-08-30, and make the file name like Logfile_2016-08-30.log
- Suffix is added with the given file name, so if there's a file named Logfle.log, then a new file will be created with a name Logfile_2016-08-30.log if not already exists,
- Other segmentations are 'NONE', 'YEAR', 'MONTH', 'DAY', 'HOUR', 'MINUTE', 'SECOND'
- Default segmentation is 'NONE', which won't create any segments and put all logs in one file.
Getters and Setters
-
You can set file path and file segmentation using setter methods, and these will impact instantly.
- Get current path and segmentation configuration using getter methods.
Logging Type
-
There are five similar yet different methods
-
All of these methods have short names.
- Output can be returned instead of putting in log file. Passing true as second parameter will return the data.
Output Format
- Output data is a string containing a preamble followed by formatted data.
-
Preamble consists of log serial number, timestamp, log type and data type. Preamble looks like following,
- When data is returned, by default it's wrapped inside tag, just to increase readability on browser.
-
Pretty formatting can be disabled and enabled by calling ugly() and pretty() methods respectively.
- json() method has a third parameter, allowing raw output. Raw output does not have any preamble or pretty formatting.
Counter
-
HelloLog has a built in counter. Counting starts from zero. Each time calling count() method will increment counter by one.
- Counter has other actions, like decrement. reset and get current value. Action strings are passed as function parameter. For all actions, counter performs the action first and then returns the counter value.
Others
-
Print timestamp. Timestamp can be returned by passing true as parameter.
- Print a simple message
That'd be all. Thanks!