Fork me on GitHub

Application - Logger

#Logger

#Overview

In computing, a logfile is a file that records either events that occur in an operating system or other software runs, or messages between different users of a communication software. Logging is the act of keeping a log. In the simplest case, messages are written to a single logfile.


Many framework applications include a logging system. Also CafeLatte(CL) has it. A widely used logging standard is syslog, defined in Internet Engineering Task Force (IETF) RFC 5424). The syslog standard enables a dedicated, standardized subsystem to generate, filter, record, and analyze log messages. This relieves software developers of having to design and code their own ad hoc logging systems.


according to PSR-3: Logger Interface. The LoggerInterface exposes eight methods to write logs to the eight RFC 5424 levels (debug, info, notice, warning, error, critical, alert, emergency).

At its core, there are 7 levels from low(Debug) to high(Emergency), you can set the log level from CONFIG

#Log Level

# Output Files(each file per one day)


$log-rw-r--r-- 1 apache apache    77548  7월 31 23:46 2017-07-31.txt
$log-rw-r--r-- 1 apache apache   155790  8월  1 23:50 2017-08-01.txt
$log-rw-r--r-- 1 apache apache  5132677  8월  2 23:59 2017-08-02.txt
$log-rw-r--r-- 1 apache apache   936806  8월  3 23:57 2017-08-03.txt
$log-rw-r--r-- 1 apache apache   125609  8월  4 23:44 2017-08-04.txt
...
...
...
$log-rw-r--r-- 1 apache apache   136286  8월 30 23:52 2017-08-30.txt
$log-rw-r--r-- 1 apache apache   255414  8월 31 23:58 2017-08-31.txt
$log-rw-r--r-- 1 apache apache   541663  9월  1 23:55 2017-09-01.txt
$log-rw-r--r-- 1 apache apache   234514  9월  2 23:58 2017-09-02.txt
$log-rw-r--r-- 1 apache apache   102370  9월  3 23:59 2017-09-03.txt
$log-rw-r--r-- 1 apache apache   420466  9월  4 23:51 2017-09-04.txt
$log-rw-r--r-- 1 apache apache   153692  9월  5 09:42 2017-09-05.txt

# Stored content in each files


[2017-09-05 09:49:46] DEBUG : ------------------------------------------------------------------
[2017-09-05 09:49:46] DEBUG : [ HEADER Params ]Host: cafe-latte.co.kr
[2017-09-05 09:49:46] DEBUG : [ HEADER Params ]Connection: keep-alive
[2017-09-05 09:49:46] DEBUG : [ HEADER Params ]Upgrade-Insecure-Requests: 1
[2017-09-05 09:49:46] DEBUG : [ HEADER Params ]User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36
[2017-09-05 09:49:46] DEBUG : [ HEADER Params ]Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng;q=0.8
[2017-09-05 09:49:46] DEBUG : [ HEADER Params ]Referer: http://cafe-latte.co.kr/
[2017-09-05 09:49:46] DEBUG : [ HEADER Params ]Accept-Encoding: gzip, deflate
[2017-09-05 09:49:46] DEBUG : [ HEADER Params ]Accept-Language: ko,en-US;q=0.8,en;q=0.6,en-GB;q=0.4,es;q=0.2,la;q=0.2
[2017-09-05 09:49:46] DEBUG : [ HEADER Params ]Cookie: PHPSESSID=67smgu7kk1l1sf************; _gat=1; _ga=GA1.3.172905427.1504566642; _gid=GA1.3.1169860802.1504566642
[2017-09-05 09:49:46] DEBUG : [ COOKIE Params ]PHPSESSID: 67smgu7kk1l1s************
[2017-09-05 09:49:46] DEBUG : [ COOKIE Params ]_gat: 1
[2017-09-05 09:49:46] DEBUG : [ COOKIE Params ]_ga: GA1.*.************.1504566642
[2017-09-05 09:49:46] DEBUG : [ COOKIE Params ]_gid: GA1.*.************.1504566642
[2017-09-05 09:49:46] DEBUG : GET
[2017-09-05 09:49:46] DEBUG : /blog
[2017-09-05 09:49:46] DEBUG : RUNTIME | 0.0666520596
[2017-09-05 09:49:50] DEBUG : ------------------------------------------------------------------
[2017-09-05 09:49:50] DEBUG : [ GET Params ]keyword: SVN
[2017-09-05 09:49:50] DEBUG : [ HEADER Params ]Host: cafe-latte.co.kr
[2017-09-05 09:49:50] DEBUG : [ HEADER Params ]Connection: keep-alive
[2017-09-05 09:49:50] DEBUG : [ HEADER Params ]Upgrade-Insecure-Requests: 1
[2017-09-05 09:49:50] DEBUG : [ HEADER Params ]User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36
[2017-09-05 09:49:50] DEBUG : [ HEADER Params ]Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng;q=0.8
[2017-09-05 09:49:50] DEBUG : [ HEADER Params ]Referer: http://cafe-latte.co.kr/blog
[2017-09-05 09:49:50] DEBUG : [ HEADER Params ]Accept-Encoding: gzip, deflate
[2017-09-05 09:49:50] DEBUG : [ HEADER Params ]Accept-Language: ko,en-US;q=0.8,en;q=0.6,en-GB;q=0.4,es;q=0.2,la;q=0.2
[2017-09-05 09:49:50] DEBUG : [ HEADER Params ]Cookie: PHPSESSID=67smgu7kk1l1sf************; _gat=1; _ga=GA1.3.172905427.1504566642; _gid=GA1.3.1169860802.1504566642
[2017-09-05 09:49:50] DEBUG : [ COOKIE Params ]PHPSESSID: 67smgu7kk1l1sf9************
[2017-09-05 09:49:50] DEBUG : [ COOKIE Params ]_gat: 1
[2017-09-05 09:49:50] DEBUG : [ COOKIE Params ]_ga: GA1.*.************.1504566642
[2017-09-05 09:49:50] DEBUG : [ COOKIE Params ]_gid: GA1.*.************.1504566642
[2017-09-05 09:49:50] DEBUG : GET
[2017-09-05 09:49:50] DEBUG : /blog/getList/?keyword=SVN
[2017-09-05 10:10:52] EMERGENCY : CafeLatte\Exception\InvalidUrlRequestException: in /home/projects/****/*******/******/Router.php:168
[2017-09-05 10:10:55] NOTICE : this is test message
[2017-09-05 10:10:55] NOTICE : this is test notice message

#How To Use

#Configure

You have to define a log level inside `cafelatte.json` source code as below


  "log": {
    "level": "debug",
    "path": "/home/projects/my_project/logs/"
  }

#EMERGENCY Level

System is unusable.


$log = new Logger();
$log->emergency("debug message");

#ALERT Level

Action must be taken immediately.


$log = new Logger();
$log->alert("debug message");

#CRITICAL Level

Critical conditions.


$log = new Logger();
$log->critical("debug message");

ERROR Level

Runtime errors that do not require immediate action but should typically


$log = new Logger();
$log->error("debug message");

#WARNING Level

Exceptional occurrences that are not errors.


$log = new Logger();
$log->warning("debug message");

#NOTICE Level

Normal but significant events.


$log = new Logger();
$log->notice("debug message");

#INFO Level

Interesting events.


$log = new Logger();
$log->info("debug message");

#DEBUG Level

Logs with an arbitrary level.


$log = new Logger();
$log->debug("debug message");