Showing
1 changed file
with
60 additions
and
0 deletions
common/models/Log.php
0 → 100644
1 | +<?php | ||
2 | + | ||
3 | +namespace common\models; | ||
4 | + | ||
5 | +use Yii; | ||
6 | + | ||
7 | +/** | ||
8 | + * This is the model class for table "{{%log}}". | ||
9 | + * | ||
10 | + * @property integer $id | ||
11 | + * @property string $content | ||
12 | + * @property string $level | ||
13 | + * @property integer $create_time | ||
14 | + */ | ||
15 | +class Log extends \yii\db\ActiveRecord | ||
16 | +{ | ||
17 | + /** | ||
18 | + * @inheritdoc | ||
19 | + */ | ||
20 | + public static function tableName() | ||
21 | + { | ||
22 | + return '{{%log}}'; | ||
23 | + } | ||
24 | + | ||
25 | + /** | ||
26 | + * @inheritdoc | ||
27 | + */ | ||
28 | + public function rules() | ||
29 | + { | ||
30 | + return [ | ||
31 | + [['content'], 'string'], | ||
32 | + [['create_time'], 'integer'], | ||
33 | + [['level'], 'string', 'max' => 10], | ||
34 | + ]; | ||
35 | + } | ||
36 | + | ||
37 | + /** | ||
38 | + * @inheritdoc | ||
39 | + */ | ||
40 | + public function attributeLabels() | ||
41 | + { | ||
42 | + return [ | ||
43 | + 'id' => 'ID', | ||
44 | + 'content' => 'Content', | ||
45 | + 'level' => 'Level', | ||
46 | + 'create_time' => 'Create Time', | ||
47 | + ]; | ||
48 | + } | ||
49 | + | ||
50 | + public function write($msg,$level = 'info') | ||
51 | + { | ||
52 | + $content = is_array($msg) ? json_encode($msg) : $msg; | ||
53 | + $this->setAttributes([ | ||
54 | + 'content'=>$content, | ||
55 | + 'level'=>$level, | ||
56 | + 'create_time'=>time() | ||
57 | + ]); | ||
58 | + return $this->save(); | ||
59 | + } | ||
60 | +} |
-
Please register or login to post a comment