Recently in the DOS command to perform PHP functions, in order to make the results of the implementation of convenient recording, so you need to add a log-generating function. It's easy, let's study together.
Windows
To satisfy the log file is generated by date.
First step: Set the current Time command (2016/08/04 Thursday).
Step two: Convert the current time date to the standard format (2016/08/04).
Step three: Turn/Switch to-(2016-08-04), why there is a third command, because the date after Windows gets is 2016/08/04, so need to turn.
Fourth step: Spell the date with the log file suffix. log.
The fifth step is to write the executed content to the log file in the specified directory, remember that the contents of the file to be recorded with the echo output, in order to successfully write to the log file.
@echo off
Set nowdate=%date%
Set tmp=%nowdate:~0,-3%
Set ymddate=%tmp:/=-%
Set File=%ymddate%.log
@echo on
D:\wamp\bin\php\php5.4.3\php.exe Index.php/ceshi/server >> D:\wamp\www\logs\rabbitmq\%file%
Note:
Create a Directory
MD d:\aaa
% NAME% equals one variable
> A pointer to a log file overwrites the log contents the next time the write
>> two append on the content of the log file
@echo off if this line of command is written in the. bat file, there is this line of code, double-click execution, DOS will not show these commands, if not, will show. bat written in the command.
@echo on allows display at the command line.
Linux
This is simpler, and Linux commands are powerful.
Create a table of contents by date
mkdir ' Date +%y%m%d '
Writes the log content to the log file, here is simple to write, the PHP program actually is same as above usage.
echo ' log content ' >> ' date +%y%m%d '. Log
Note: There must be a space after date, or not recognized, will be an error. ' This symbol is the key on the TAB key in the English state ~ '.
This article is from the "PHP Engineer's Blog" blog, please be sure to keep this source http://340411305.blog.51cto.com/7627178/1834396
Implementing log Write file functionality under Linux and Windows