自定义日志文件写日志

use yii\log\FileTarget;

$time = microtime(true);

$log = new FileTarget();

$log->logFile =  Yii::$app->getRuntimePath()."/logs/a.log‘;

$log->message[] = [‘test‘,1,‘application‘,$time];

$log->export();

/*
* [0] => message (mixed, can be a string or some complex data, such as an exception object)
* [1] => level (integer)
* [2] => category (string)
* [3] => timestamp (float, obtained by microtime(true))
* [4] => traces (array, debug backtrace, contains the application code call stacks)
*/
传递参数按照这些信息进行传递就可以了。最后记住重要的一点
$log->messages[] 别忘了加[]

时间: 2024-08-04 11:17:55

自定义日志文件写日志的相关文章

Yii2 自定义日志文件写日志

头部引入log类use yii\log\FileTarget; $time = microtime(true);$log = new FileTarget();$log->logFile = Yii::$app->getRuntimePath() . '/logs/zhidemy.com.log'; //文件名自定义$log->messages[] = ['test',1,'application',$time];$log->export(); 这样基本就能写出来了,先看一下$lo

C++ RAII手法实现的线程安全的日志文件写例子

#include <iostream> #include <fstream> #include <string> #include <cstdarg> #include <cstdio> #include <pthread.h> // MutexLock 封装互斥锁的接口 class MutexLock { public: MutexLock() { pthread_mutex_init(&mutex_, NULL); } M

Java日志使用slf4j 配置log4j后,有日志文件 但日志文件内容为空

SLF4J的全称是Simple Logging Facade for Java,即简单日志门面. SLF4J并不是具体的日志框架,而是作为一个简单门面服务于各类日志框架,如java.util.logging, logback和log4j. SLF4J支持{}作为占位符,等价于C语言中的%s,而不必再进行字符串的拼接,效率有显著的提. 1.slf4j使用 引入包 slf4j-api-1.6.2.jar import org.slf4j.Logger; import org.slf4j.Logger

SQL Server 2008 清空删除日志文件(瞬间日志变几M)

sql 在使用中每次查询都会生成日志,但是如果你长久不去清理,可能整个硬都堆满哦,笔者就遇到这样的情况,直接网站后台都进不去了.下面我们一起来学习一下如何清理这个日志吧 SQL2008清空删除日志: 方法一: USE [master] GO ALTER DATABASE AFMS SET RECOVERY SIMPLE WITH NO_WAIT GO ALTER DATABASE AFMS SET RECOVERY SIMPLE GO USE AFMS GO DBCC SHRINKFILE (N

vue 自定义js文件 写方法

//全局函数方法 exports.install = function(Vue, options) { Vue.prototype.$popup = function(msg, time) { //msg 为内容 //time 弹窗显示时间 time = isNaN(time) ? 3000 : time; var m = document.createElement('div'); m.className="popupall" m.innerHTML = msg; document.

rsync服务同步、日志文件、screen工具

10.32 rsync通过服务同步(上) 在使用该方法进行同步之前需要先在服务的开启相应服务同时要监听一个端口(可自定义),默认是监听873端口,开启服务之前编辑rsync配置文件"/etc/rsyncd.conf"(将服务添加进去)然后直接使用命令:"rsync --daemon(服务名称)"进行同步.或者将配置文件写到一个自定义文件中,使用命令"rsync --configfile"进行同步.配置完成后客户端可以通过指定端口与服务端进行通信.

mysql 的日志文件

mysql的日志文件 日志文件大致分为  error log, binary log, query log, slow query log, innodb redo log ;如图: 1.error log the error log file contains information indicating when mysqld was started and stopped also any critical errors that occur while the server is run

SqlSever基础 设置数据库文件与日志文件的逻辑名称

1 code 1 select * from sysdatabases 2 3 drop database helloworld 4 5 create database helloworld 6 7 --设置mdf文件的属性 8 on primary 9 ( 10 name = 'aHelloWorldLogic', --mdf文件的逻辑名字(不是文件名字) 11 filename = 'C:\Users\Administrator\Desktop\aHelloWorld.mdf', --mdf

SqlSever基础 设置数据库文件与日志文件的初始大小

1 code 1 select from sysdatabases 2 3 drop database helloworld 4 5 create database helloworld 6 7 --设置mdf文件的属性 8 on primary 9 ( 10 name = 'aHelloWorldLogic', --mdf文件的逻辑名字(不是文件名字) 11 filename = 'CUsersAdministratorDesktopaHelloWorld.mdf', --mdf文件的存储路径