Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Realize the function of writing log to file under linux and windows

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

Recently, I am doing the function of executing php under the dos command, in order to make the result of execution easy to record, so I need to add a function to generate log. It's very simple. Let's study it together.

Windows

To satisfy that the log files are generated by date.

Step 1: set the command for the current time (Thursday, 2016-08-04).

Step 2: convert the current time and date to standard format (2016-08-04).

Step 3: convert / convert to-(2016-08-04), why is there a third command? because the date after windows acquisition is 2016-08-04, it needs to be transferred.

Step 4: spell the date with the log file suffix .log.

Step 5: write the content after execution to the log file under the specified directory, and remember to output the content to be recorded in the file with echo, so that it can be written into the log file smoothly.

@ 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% is equivalent to a variable

A point to the log file will overwrite the log contents the next time it is written

Two are appended based on the contents of the log file

@ echo off if the command is written in the .bat file, if you have this line of code, double-click and execute, the commands will not be displayed in dos, if not, the commands written in .bat will be displayed.

@ echo on allows display on the command line.

Linux

This is relatively simple, the linux command is more powerful.

Create a catalog by date

Mkdir date +% y%m%d

Write the log contents to the log file, which is simply written here, and the PHP program is actually the same as the above.

Echo 'Log contents' > > date + y%m%d.log

Note: there must be a space after date, otherwise an error will be reported if it is not recognized. This symbol is the button above the tab key in English.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report