Implementing log Write file functionality under Linux and Windows

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.