├── fxmanifest.lua ├── LICENSE ├── Readme.md └── log.lua /fxmanifest.lua: -------------------------------------------------------------------------------- 1 | fx_version 'adamant' 2 | game 'gta5' 3 | description 'D-Logging from Deun Services' 4 | version '1.0' 5 | 6 | lua54 'yes' 7 | 8 | shared_script { 'log.lua' } 9 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 DeunService 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Readme.md: -------------------------------------------------------------------------------- 1 | ## Links 2 | 3 | Homepage > https://deun.xyz/ 4 | 5 | Discord > https://deun.xyz/discord 6 | 7 | Store > https://store.deun.xyz 8 | 9 | Docs > https://deun-services.gitbook.io/deun/ 10 | 11 | ## Installation 12 | 13 | 1. Drag it in your resource folder 14 | 2. add this in your server.cfg ( ) 15 | ensure d-logging 16 | 17 | ### Configuration 18 | 19 | In the top of the log.lua you can find everything you need to configure. 20 | 21 | ### How to add this to your scripts 22 | 23 | Add this to the fxmanifest- / resource.lua 24 | 25 | ```lua 26 | shared_script { 27 | '@d-logging/log.lua', 28 | } 29 | ``` 30 | 31 | With this you can acess all the functions 32 | 33 | ## Functions 34 | 35 | ```lua 36 | Log.trace("trace") 37 | Log.debug("debug") 38 | Log.info("info") 39 | Log.warn("warn") 40 | Log.error("error") 41 | Log.fatal("fatal") 42 | Log.discord("discord") 43 | 44 | ``` 45 | 46 | Here an Image where you can see how it looks 47 | 48 | ![Screenshot 2022-11-24 at 21 38 16](https://user-images.githubusercontent.com/116830002/203861349-98dfc31a-edfa-4f8e-a493-7ce2210afab1.png) 49 | 50 | ## When to use which level 51 | 52 | Thats something you have to decide yourself which level you think is necessary for your purpose, but here is an small guideline which could be helpful. 53 | 54 | **Trace** - More detailed information then Debug which are not really necessary to have but still help to follow the flow of your resource e.g. which functions are triggerd. 55 | 56 | **Debug** - Log everything you as developer need to see if your script works but is not to detailed 57 | 58 | **Info** - Log stuff which is information based like when the script is started, or notifications or stuffe like this 59 | 60 | **Warn** - Log stuff that doenst stuff the resource but might be dangerous so we should take a look at it, like slow querys 61 | 62 | **Error** - Stuff which causes a function or event to work and is very dangerous. 63 | 64 | **Fatal** - If the complete script could crash 65 | 66 | **Discord** - You can setup an webhook for this to send logs via the webhook to your discord channel 67 | -------------------------------------------------------------------------------- /log.lua: -------------------------------------------------------------------------------- 1 | Log = { 2 | -- Set the lowest log level. If the loglevel is trace it will show all levels above. If you set it to e.g. error just error and fatal will be shown. 3 | -- It would recommend this on live servers. For test servers enable everything 4 | LogLevel = "error", 5 | -- If enabled the diffrent levels will have different colors in the Console 6 | UserColors = true, 7 | -- These are all the available Log levels, you can acess. You can use them by simply triggering the function Log.level e.g. Log.trace 8 | Levels = { 9 | { 10 | name = 'trace', 11 | color = "\27[34m", 12 | print = true, 13 | }, 14 | { 15 | name = 'debug', 16 | color = "\27[36m", 17 | print = true, 18 | }, 19 | { 20 | name = 'info', 21 | color = "\27[33m", 22 | print = true, 23 | }, 24 | { 25 | name = 'warn', 26 | color = "\27[35m", 27 | print = true, 28 | }, 29 | { 30 | name = 'error', 31 | color = "\27[31m", 32 | file = "logs/%s.txt", 33 | print = true, 34 | }, 35 | { 36 | name = 'fatal', 37 | -- You can just use ansi colors 38 | color = "\27[41m", 39 | -- If you set an file, it will create an file in fx directory of your server where you can see all e.g. fatal logs. 40 | -- To disable this, simple remove the line or add it to the level you wish. 41 | -- %s is an placeholder for the name of the resource where the prints come from 42 | file = "logs/%s.txt", 43 | -- You can set this to false if you dont want to have the prints in the server console 44 | -- It still wll save them to the file, if you have set one 45 | print = true, 46 | }, 47 | { 48 | name = 'discord', 49 | color = "\27[34m", 50 | -- You could add an webhook to every option if you want 51 | -- Set here the webhook of one of your discord channels 52 | webhook = "", 53 | print = false, 54 | }, 55 | }, 56 | -- The scripts who are listed here wont be displayed in your console if they have d-logging prints 57 | HideScripts = { 58 | -- 'd-phone' 59 | }, 60 | -- If this isnt empty just the scripts, which are in this array will be displayed 61 | ShowOnlyScript = { 62 | -- 'd-phone', 63 | } 64 | } 65 | 66 | local overloglevel = false 67 | Citizen.CreateThread(function() 68 | for i, v in pairs(Log.Levels) do 69 | Log[v.name] = function(msg) 70 | if OverlogLevel(v.name) == true then 71 | for _, script in pairs(Log.HideScripts) do 72 | if script == GetCurrentResourceName() then 73 | return 74 | end 75 | end 76 | 77 | if #Log.ShowOnlyScript > 0 then 78 | local found = false 79 | for _, script in pairs(Log.ShowOnlyScript) do 80 | if script == GetCurrentResourceName() then 81 | found = true 82 | end 83 | end 84 | 85 | if found == false then 86 | return 87 | end 88 | end 89 | 90 | local color = "" 91 | local info = debug.getinfo(2, "Sl") 92 | local lineinfo = info.short_src .. ":" .. info.currentline 93 | local nameupper = v.name:upper() 94 | if Log.UserColors then color = v.color end 95 | if v.print == nil or v.print and v.print == true then 96 | local text = string.format("%s[%-6s%s]%s [%s] %s", 97 | IsDuplicityVersion() and color or '', 98 | nameupper, 99 | IsDuplicityVersion() and os.date("%H:%M:%S") or '', 100 | Log.UserColors and "\27[0m" and IsDuplicityVersion() or "", 101 | lineinfo, 102 | msg) 103 | 104 | print(text) 105 | end 106 | 107 | if v.file and IsDuplicityVersion() then 108 | local fp = io.open(string.format(v.file, GetCurrentResourceName()), "a") 109 | if not fp then 110 | os.execute("mkdir logs") 111 | fp = io.open(string.format(v.file, GetCurrentResourceName()), "a") 112 | end 113 | 114 | local str = string.format("[%-6s%s] %s: %s\n", 115 | nameupper, os.date(), lineinfo, msg) 116 | fp:write(str) 117 | fp:close() 118 | end 119 | 120 | if v.webhook and IsDuplicityVersion() then 121 | sendDiscordLog(v.webhook, msg) 122 | end 123 | end 124 | end 125 | end 126 | end) 127 | 128 | function OverlogLevel(level) 129 | local i = 0 130 | local overi = 0 131 | for i_, v in pairs(Log.Levels) do 132 | if v.name == level then 133 | i = i_ 134 | end 135 | if v.name == Log.LogLevel or Log.LogLevel:upper() == "ALL" then 136 | overi = i_ 137 | end 138 | end 139 | 140 | if i >= overi then 141 | return true 142 | else 143 | return false 144 | end 145 | end 146 | 147 | function sendDiscordLog(webhook, description) 148 | PerformHttpRequest(webhook, function(err, text, headers) 149 | end, 'POST', json.encode({ 150 | username = " ", 151 | embeds = { { 152 | ["color"] = 10650848, 153 | ["author"] = { 154 | ["name"] = "D-Logging", 155 | }, 156 | ["description"] = tostring(description), 157 | ["footer"] = { 158 | ["text"] = os.date("%H:%M:%S"), 159 | }, 160 | } }, 161 | avatar_url = 'https://cdn.discordapp.com/attachments/890638170247561277/939834062674206770/blackpurple.png' 162 | }), { 163 | ['Content-Type'] = 'application/json' 164 | }) 165 | end 166 | --------------------------------------------------------------------------------